Ruby on rails: uploading images using authentication / authorization / timeouts

I have little doubt about downloading files. I am creating an application in which I use attachment_fu with Amazon s3 to upload files. So far, everything is working well on the download side. Now it's time to start downloading files. Here's what I need, a user’s registered search and viewing images, and they should be able to add files to the download basket (say, her shopping basket). Finally, the user should be able to download these files from S3, probably as an archived file.

Is there any plugin / gem where I can use for this?

+3
source share
1 answer

The disadvantage of providing the client with a zip file of all files is that you need to first pull all the files from S3 back to your server, and then secure them.

You can do this if you want, but it will take a little time, you will not want to do this synchronously, as part of a browser request. Instead, do it as a background job using delayed_job or the like.

To do the actual zipping, use Zlib :: GzipWriter. See http://ruby-doc.org/core/classes/Zlib/GzipWriter.html - this is part of the standard Ruby

Could you:

  • write the user the actual zip file as an attachment
  • write the user a link to the zip file on your server.
  • or upload the zip file to s3, then send the link to the zip file to s3

/, zip ...

, , .

S3 URL- S3, . ( S3, .) , -fu aws-s3 gem:

# I added this as a method to my model for the files stored in S3
def authenticated_s3_url
  # return a publicly usable url
  connect_to_aws # a local method which connects/re-connects to s3
  S3Object.url_for(full_filename, 
             bucket_name, 
            :expires_in => 60 * 60) # 1 hour
end
+3

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