我有一个存储桶,默认ACL设置为私有。我想生成预签名的url并将其分发给用户,以便他们可以上传文件,并且上传后需要该文件可公开访问。
我可以生成预签名的url并上传文件,但该文件始终保持私有状态。如果我在创建签名URL时将ACL设置为“公开读取”,则 getSignedUrl()会生成签名URL,但对该签名URL的PUT请求将导致访问被拒绝。
var params = {
Bucket: "bucket name",
Key: "file key name",
Expires: 3600,
ACL:"public-read",
ContentType: "application/octet-stream"
};
s3.getSignedUrl("putObject", params);
存储桶可以包含私人文件或公共访问文件,我想在创建签名URL时设置隐私。我怎样才能做到这一点?
我正在使用Amazon javascript SDK。
答案 0 :(得分:0)
此处来自AWS-S3文档...
看起来您必须用困难的方式做到这一点。
getSignedUrl(operation, params, callback) ⇒ String?
Note: You must ensure that you have static or previously resolved credentials if you
call this method synchronously (with no callback), otherwise it may not properly sign
the request. If you cannot guarantee this (you are using an asynchronous credential provider,
i.e., EC2 IAM roles), you should always call this method with an asynchronous callback.
Note: Not all operation parameters are supported when using pre-signed URLs. Certain parameters,
such as SSECustomerKey, ACL, Expires, ContentLength, or Tagging must be provided as headers when
sending a request.
If you are using pre-signed URLs to upload from a browser and need to use these fields,
see createPresignedPost()....