How do I translate "File.open" to be S3 compatible?
I have this line..
@organization.sea开发者_JAVA百科rch_image = File.open(@photo.photo.path(:original))
Except that 's looking for something local, and all my photos are on S3 now. How would I translate that to opening a file on S3?
I think what you should do is download/stream the image in S3 and write it to a new file then use the new file.
open('newpic.png', 'w') do |file|
S3Object.stream('pic.png', 'bucket_name') do |chunk|
file.write chunk
end
end
#Write the streamed file to newpic.png then use newpic.png.
You have two options that come to mind:
- Use the S3 Ruby bindings and access your data using the S3 provided abstractions.
- Continue with the filesystem abstraction but bind S3 to a local proxy filesystem using FUSE which is available for *nix/OSX (but not for Windows as far as I know) making this approach less generally applicable. This is probably less efficient than option 1 too.
精彩评论