How to translate "File.open" to compatibility with S3?

I have this line.

@organization.search_image = File.open(@photo.photo.path(:original))

Besides looking for something local, and all my photos are now on S3. How would I do to open a file on S3?

+3
source share
2 answers

I think what you should do is upload / transfer the image to S3 and write it to a new file, and 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.
+1
source

You have two options that come to mind:

  • Use S3 Ruby bindings and access your data using the S3 provided abstractions.
  • , S3 FUSE, * nix/OSX ( Windows, ), . , , , 1.
0

Source: https://habr.com/ru/post/1755597/


All Articles