简体   繁体   English

Laravel S3 - arn 和 kms 密钥

[英]Laravel S3 - arn and kms key

Client has provided me below details:-客户向我提供了以下详细信息:-

AWS_ACCESS_KEY_ID=XXX
AWS_SECRET_ACCESS_KEY=XXX
AWS_DEFAULT_REGION=XXX
AWS_BUCKET=XXX
ARN: arn:aws:s3:::XXX
KMS Key: XXX

Image is uploaded successfully on aws server.图像已成功上传到 aws 服务器。 but when i tried to open the url, access denied is coming.但是当我试图打开 url 时,访问被拒绝。

Image upload code as below:-图片上传代码如下:-

$filePath = "users/" . $user_id . "/". $name;
Storage::disk('s3')->put($filePath, file_get_contents($file));
$fileName = Storage::disk('s3')->url($filePath);

Yes, by default, AWS S3 implements this restriction for security purposes.是的,默认情况下,AWS S3 出于安全目的实施此限制。 You can meet your needs by doing this:您可以通过这样做来满足您的需求:

$publicTime = 10; // Your file will be available 10 minutes
$filePath = "users/" . $user_id . "/". $name;

// Upload file 
Storage::disk('s3')->put($filePath, file_get_contents($file));

// Generate temporary URL
$url = Storage::disk('s3')->temporaryUrl($filePath, now()->addMinutes($publicTime))

With this method, you can keep your S3 buckets private while providing public access for your files.使用此方法,您可以在为文件提供公共访问权限的同时保持 S3 存储桶的私密性。

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

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