Im generating a pre-signed url so i can upload a file to a S3 bucket.
我生成一个预先签名的URL,以便我可以将文件上传到S3存储桶。
var params = {Bucket: 'xxxxxxx', Key: 'key', Expires: 60};
var url = s3.getSignedUrl('putObject', params);
console.log('The URL is', url);
The Key parameter is required, but i cant find in the documentation how can i generate this.
Key参数是必需的,但我无法在文档中找到如何生成它。
If i submit an upload using this generated URL:
如果我使用此生成的URL提交上传:
xhr.open("PUT", url);
xhr.setRequestHeader('Content-Type', files[0].type);
xhr.setRequestHeader('x-amz-acl', 'authenticated-read');
xhr.send(files[0]);
It returns this error SignatureDoesNotMatch
它返回此错误SignatureDoesNotMatch
Am i missing something on the url signing method?
我错过了网址签名方法的内容吗?
1 个解决方案
#1
Just figured this out. Parameters to sign URL must have all the things that im sending on the header and the Key is the file name.
刚想通了。签名URL的参数必须包含我在标题上发送的所有内容,而Key是文件名。
var params = {Bucket: 'xxxxxxx', Key: 'filename.ext', Expires: 60, ACL:'authenticated-read', ContentType: 'applicattion/xxxxx'};
This fixed my problem.
这解决了我的问题。
#1
Just figured this out. Parameters to sign URL must have all the things that im sending on the header and the Key is the file name.
刚想通了。签名URL的参数必须包含我在标题上发送的所有内容,而Key是文件名。
var params = {Bucket: 'xxxxxxx', Key: 'filename.ext', Expires: 60, ACL:'authenticated-read', ContentType: 'applicattion/xxxxx'};
This fixed my problem.
这解决了我的问题。