开发者

How do I translate "File.open" to be S3 compatible?

开发者 https://www.devze.com 2023-01-08 07:25 出处:网络
I have this line.. @organization.sea开发者_JAVA百科rch_image = File.open(@photo.photo.path(:original))

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:

  1. Use the S3 Ruby bindings and access your data using the S3 provided abstractions.
  2. 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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号