This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "Creating an SSH key for you..." | |
| ssh-keygen -t rsa | |
| printf "Please add this public key to Github" | |
| printf "https://github.com/account/ssh" | |
| read -pr "Press [Enter] key after this..." | |
| echo "Installing xcode-stuff" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -X POST -w "@curl-format.txt" -o /dev/null -s -F image=@example.png localhost:3000/uploads | |
| time_total: 0.014959s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UploadsController < ApplicationController | |
| def create | |
| upload = Upload.new | |
| upload.image = params[:image] | |
| upload.save! | |
| head :ok | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PromoteJob | |
| include Sidekiq::Worker | |
| def perform(attacher_class, record_class, record_id, name, file_data) | |
| attacher_class = Object.const_get(attacher_class) | |
| record = Object.const_get(record_class).find(record_id) # if using Active Record | |
| attacher = attacher_class.retrieve(model: record, name: name, file: file_data) | |
| attacher.atomic_promote | |
| rescue Shrine::AttachmentChanged, ActiveRecord::RecordNotFound |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Upload < ApplicationRecord | |
| include ImageUploader::Attachment(:image) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'image_processing/mini_magick' | |
| class ImageUploader < Shrine | |
| Attacher.derivatives do |original| | |
| magick = ImageProcessing::MiniMagick.source(original) | |
| { | |
| small: magick.resize_to_limit!(300, 300), | |
| medium: magick.resize_to_limit!(500, 500), | |
| large: magick.resize_to_limit!(800, 800), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'shrine' | |
| require 'shrine/storage/file_system' | |
| Shrine.storages = { | |
| cache: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/cache'), # temporary | |
| store: Shrine::Storage::FileSystem.new('public', prefix: 'uploads'), # permanent | |
| } | |
| Shrine.plugin :activerecord # AR integration | |
| Shrine.plugin :derivatives, create_on_promote: true # Save image in multiple versions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "image_processing/mini_magick" | |
| class ImageUploader < Shrine | |
| Attacher.derivatives do |original| | |
| magick = ImageProcessing::MiniMagick.source(original) | |
| { | |
| small: magick.resize_to_limit!(300, 300), | |
| medium: magick.resize_to_limit!(500, 500), | |
| large: magick.resize_to_limit!(800, 800), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gem 'shrine', '~> 3.0' | |
| gem 'sidekiq', '~> 6.1', '>= 6.1.2' | |
| gem "image_processing", '~> 1.8' # Used to create image versions |