上传时 Amazon S3 存储桶 MalformedXML 错误
Amazon S3 bucket MalformedXML error when uploading
我正在尝试将图片上传到我的 Amazon S3 存储桶。这是我的 XMLHttpRequest 的代码:
var form_data = new FormData();
form_data.append(filename, file);
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'https://bucket-name.s3.amazonaws.com', true);
xhr.send(form_data);
我已经将 CORS 配置如下:
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
不幸的是,我在尝试上传时不断收到以下错误:
PUT https://bucket-name.s3.amazonaws.com 400 (Bad Request)
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>MalformedXML</Code><Message>The XML you provided was not well-formed or
did not validate against our published schema</Message><RequestId>6188AA51D1EE6B38</RequestId>
<HostId>f3d5Aj8bMyMOJywRnYKH/tBXRHCDWFvNzcb4ejs9F4/IulP1P2n0XoN1mDq7LpQgL/RIsW1c6RA=</HostId></Error>
有谁知道我做错了什么吗?
您似乎正在向存储桶本身发送 PUT 请求,但没有对象名称。 S3 将此解释为 PUT BUCKET 请求,并期望正文是 CreateBucketConfiguration XML 文档。
要上传文件,您的 XHR 公开调用应类似于:
xhr.open('PUT', 'https://bucket-name.s3.amazonaws.com/' + filename, true);
documentation 中有一个示例请求。
我正在尝试将图片上传到我的 Amazon S3 存储桶。这是我的 XMLHttpRequest 的代码:
var form_data = new FormData();
form_data.append(filename, file);
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'https://bucket-name.s3.amazonaws.com', true);
xhr.send(form_data);
我已经将 CORS 配置如下:
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>http://localhost:3000</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
不幸的是,我在尝试上传时不断收到以下错误:
PUT https://bucket-name.s3.amazonaws.com 400 (Bad Request)
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>MalformedXML</Code><Message>The XML you provided was not well-formed or
did not validate against our published schema</Message><RequestId>6188AA51D1EE6B38</RequestId>
<HostId>f3d5Aj8bMyMOJywRnYKH/tBXRHCDWFvNzcb4ejs9F4/IulP1P2n0XoN1mDq7LpQgL/RIsW1c6RA=</HostId></Error>
有谁知道我做错了什么吗?
您似乎正在向存储桶本身发送 PUT 请求,但没有对象名称。 S3 将此解释为 PUT BUCKET 请求,并期望正文是 CreateBucketConfiguration XML 文档。
要上传文件,您的 XHR 公开调用应类似于:
xhr.open('PUT', 'https://bucket-name.s3.amazonaws.com/' + filename, true);
documentation 中有一个示例请求。