简体   繁体   中英

In Carrierwave how to let a user download an s3 file only once?

Let's say I upload a file to S3 using Carrierwave in my Rails application. I need to make sure :

  • The file is hidden (The actual url to be hidden)
  • Let a user download the file from a temporarily generated URL which allows only 1 download. If we retype that url it won't let the user download the file

How can I achieve this?

You need to do it code itself. You need to track record of downloaded file.

For this you need to create a table that hold information for user and file that already downloaded.

To hide actual s3 url, You need to first read file in your code from s3 and available that file to user with send_data .

xyz = Xyz.find(params[:id])
data = open(xyz_file_path).read
send_file data, filename: file_name_that_you_want, 
  type: file_content_type, stream: 'true', 
  :x_sendfile => true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM