The code below resizes my image. But I'm not sure how to write it to a temp or blob file so that I can upload it to s3.
origImage = MiniMagick::Image.open(myPhoto.tempfile.path) origImage.resize "200x200" thumbKey = "tiny-#{key}" obj = bucket.objects[thumbKey].write(:file => origImage.write("tiny.jpg"))
I can only download the source file to s3 with the following command:
obj = bucket.objects[key].write('data') obj.write(:file => myPhoto.tempfile)
I think I want to create a temporary file, read the image file and load it:
thumbFile = Tempfile.new('temp') thumbFile.write(origImage.read) obj = bucket.objects[thumbKey].write(:file => thumbFile)
but the origImage class does not have a read command.
UPDATE: I read the source code and found out about this command
And s3 api docs say that you can transfer content using a code block, for example:
obj.write do |buffer, bytes|
How do I change my code so that
origImage.write (here s3stream)
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html
UPDATE 2
This code successfully uploads a thumbnail file to s3. But I will still love how to do it. I think it would be much more effective.
#resize image and upload a thumbnail smallImage = MiniMagick::Image.open(myPhoto.tempfile.path) smallImage.resize "200x200" thumbKey = "tiny-#{key}" newFile = Tempfile.new("tempimage") smallImage.write(newFile.path) obj = bucket.objects[thumbKey].write('data') obj.write(:file => newFile)