我的应用程序中有一个下载链接,用户应该能够下载存储在s3上的文件.这些文件可以在网址上公开访问,看起来像
https://s3.amazonaws.com/:bucket_name/:path/:to/:file.png
Run Code Online (Sandbox Code Playgroud)
下载链接在我的控制器中执行操作:
class AttachmentsController < ApplicationController
def show
@attachment = Attachment.find(params[:id])
send_file(@attachment.file.url, disposition: 'attachment')
end
end
Run Code Online (Sandbox Code Playgroud)
但是当我尝试下载文件时出现以下错误:
ActionController::MissingFile in AttachmentsController#show
Cannot read file https://s3.amazonaws.com/:bucket_name/:path/:to/:file.png
Rails.root: /Users/user/dev/rails/print
Application Trace | Framework Trace | Full Trace
app/controllers/attachments_controller.rb:9:in `show'
Run Code Online (Sandbox Code Playgroud)
该文件肯定存在,可以在错误消息的URL中公开访问.
如何允许用户下载S3文件?
ruby ruby-on-rails amazon-s3 ruby-on-rails-3 ruby-on-rails-3.2
我有一个 Rails 6 应用程序,注册用户(所有者)可以在 S3 上上传文件 -图像/视频,然后所有者可以向其他用户(邀请)提供访问权限以查看他们上传的内容。
有没有办法限制文件访问,以便只有所有者才能下载他上传的文件(图像/视频),从而对其他非所有者/受邀用户进行限制。。视频/图像不应该通过右键单击并保存/下载来如此轻松地下载。
注意- 上传的文件还包括大视频(mp4 和 HLS 流),因此其他受邀用户可以查看它们,但无法下载,除非他们是所有者/上传者,因为文件来自 AWS Cloudfront 的视频和 S3(如果他们是)是图像。
协会的设置如下 -
User has one role
User has many images/videos, each residing in his own folder on s3(`bucket/user_id/image_slug/` or `bucket/user_id/video_slug/`)
User has many invitations(must be view only access to owners file)
Run Code Online (Sandbox Code Playgroud)
不确定,什么是正确的方法,可以 -
让我知道最适合这种方法的逻辑是什么。