var fu1 = document.getElementById("FileUpload1");
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得fileupload控件的文件名 id FileUpload1
我正在尝试生成一个预签名的URL,然后通过浏览器将文件上传到S3。我的服务器端代码如下所示,它生成URL:
let s3 = new aws.S3({
// for dev purposes
accessKeyId: 'MY-ACCESS-KEY-ID',
secretAccessKey: 'MY-SECRET-ACCESS-KEY'
});
let params = {
Bucket: 'reqlist-user-storage',
Key: req.body.fileName,
Expires: 60,
ContentType: req.body.fileType,
ACL: 'public-read'
};
s3.getSignedUrl('putObject', params, (err, url) => {
if (err) return console.log(err);
res.json({ url: url });
});
Run Code Online (Sandbox Code Playgroud)
这部分似乎工作正常。如果我将其记录下来并将其传递到前端,则可以看到该URL。然后在前端,我尝试使用axios和签名的URL上传文件:
.then(res => {
var options = { headers: { 'Content-Type': fileType } };
return axios.put(res.data.url, fileFromFileInput, options);
}).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
}
Run Code Online (Sandbox Code Playgroud)
这样,我得到了403 Forbidden错误。如果我点击链接,则会有一些包含更多信息的XML:
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request …
Run Code Online (Sandbox Code Playgroud)