Skip to content

Instantly share code, notes, and snippets.

@kirs
Forked from Olefine/upload.rb
Last active December 21, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirs/6281764 to your computer and use it in GitHub Desktop.
Save kirs/6281764 to your computer and use it in GitHub Desktop.
class MessageImageWorker
@queue = :message_image_queue
def self.perform(message_id, image_path)
MessageImage.create!(message_id: message_id, image: image_path)
end
end
class AmazonImageUploader
def initialize(message_id, file)
name = file[0][:image].original_filename
directory = "public/uploads/"
path = File.join(directory, name)
File.open(path, "wb") { |f| f.write(file[0][:image].read) }
@path = path
@message_id = message_id
end
def process
Resque.enqueue(MessageImageWorker, @message_id, @path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment