我正在使用 nestjs 并且我想上传到 amazon s3,但是每个请求都失败并且错误是:
POST requires exactly one file upload per request
这是我的代码实现:
const formData = new FormData();
formData.append('policy', clientPayload.policy);
formData.append('key', clientPayload.key);
formData.append('x-amz-signature', clientPayload['x-amz-signature']);
formData.append('x-amz-algorithm', clientPayload['x-amz-algorithm']);
formData.append('x-amz-date', clientPayload['x-amz-date']);
formData.append('x-amz-credential', clientPayload['x-amz-credential']);
formData.append('success_action_status', '201');
formData.append('success_action_redirect', '');
formData.append('file', file.path);
try {
const data = await this.http
.post(AppConfig.awsServices.bucketUrl, formData, {
headers: {
'content-type':
'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW',
},
})
.toPromise();
这是回应:
data: '<?xml version="1.0" encoding="UTF-8"?>\n' +
'<Error><Code>InvalidArgument</Code><Message>POST requires exactly one file upload per request.</Message><ArgumentName>file</ArgumentName><ArgumentValue>0</ArgumentValue><RequestId>D602243726B03B53</RequestId><HostId>qjLwo8jak8yb3iWOXp4fbqAw391MW7d/3/9r8AzqA20hAvYd1Kgj0PJIAEv+v9sMckixT9WtUoA=</HostId></Error>'
这里还有图片附件:
这是我试图从文档中实现的请求:
https://dev.vdocipher.com/api/docs/book/upload/file.html
萧十郎
相关分类