質問

I'm attempting to upload the full size image that comes from a post, then thumbnail it and put the thumbnail on S3. However, I'm running into a strange issue where the my resize code seems to be affecting the full size image, even though S3 should be storing it prior to any resize occuring. Here is a snippet of code illustrating it...

AWS::S3::S3Object.store(fullPath, open(params[:photo][:tempfile]), BS.config[:service][:aws][:bucket], :access => :public_read)

  thumbnail = MiniMagick::Image.open(params[:photo][:tempfile].path)
  thumbnail.combine_options do |c|
    c.resize('200x200^')
    c.gravity('center')
    c.crop('200x200+0+0')
  end

  AWS::S3::S3Object.store(thumbnailPath, thumbnail.to_blob, BS.config[:service][:aws][:bucket], :access => :public_read)
役に立ちましたか?

解決

Even though you call store before doing the resize, there's no guarantee the code for the resize does not begin before the code for storing has finished, and since there's network latency involved and the docs for S3Object specifically say that larger files (of which image files could surely be classed) will get sent up in chunks, it's quite possible you're modifying a file that hasn't yet been sent.

Whatever the reason, the simple answer is to make a copy of the file and resize that.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top