简体   繁体   English

Rails的Carrierwave Fog隐藏S3目录

[英]Rails Carrierwave Fog hide s3 directory

I want to let the user download file directly from S3, but does not want to expose the full directory. 我想让用户直接从S3下载文件,但不想公开完整目录。 Currently I am able to achieve that with AWS::S3 library by doing 目前,我可以通过以下方式使用AWS::S3库实现该目标

S3Object.url_for('beluga_baby.jpg', 'marcel_molina')

and it will give me url like: 它将给我网址,例如:

http://s3-ap-southeast-1.amazonaws.com/bucketname/filename.png?AWSAccessKeyId=key&Expires=exp&Signature=signature

Is this achievable with fog alone? 仅凭雾就可以做到吗? I tried to config fog like so: 我试图像这样配置雾:

config.fog_public = false
config.fog_authenticated_url_expiration = 600 # 10 minutes

But the directory of the file is still exposed, just with an expiration. 但是该文件的目录仍然是公开的,只是到期了。

"https://bucketname.s3-ap-southeast-1.amazonaws.com/uploads/course_material/file/id/filename.png?AWSAccessKeyId=key&Signature=signature&Expires=exp"

The url with the expiration is likely what you'll want (if you look closely at the result from S3Object you'll see it is that way also). 带有到期日期的url可能是您想要的(如果您仔细查看S3Object的结果,您也会发现它也是这种方式)。 Even if someone knows the name of the bucket and the path, they should not have access, unless you explicitly make the bucket public. 即使有人知道存储桶的名称和路径,他们也无权访问,除非您显式将存储桶公开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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