【发布时间】:2017-08-17 21:10:47
【问题描述】:
我有一个 openstack 对象存储容器,我正在尝试直接从浏览器上传文件。
根据文档here,我可以使用PUT 请求上传文件,我正在使用Angularjs 提供的$http.put 方法执行此操作,如下所示。
$http.put(temporaryUploadUrl,
formData,
{
headers: {
'Content-Type': undefined
}
}
).then(function (res) {
console.log("Success");
});
文件上传成功,验证没有问题,并给我一个201 Created 响应。然而,该文件现在在其顶部和底部包含垃圾行,因为它是使用 FormData() 发送的多部分请求。
上传前的示例文件内容:
Some sample text
here is more text
here is some other text
从openstack容器下载回来后的文件内容:
------WebKitFormBoundaryTEeQZVW5hNSWtIqS
Content-Disposition: form-data; name="file"; filename="c.txt"
Content-Type: text/plain
Some sample text
here is more text
here is some other text
------WebKitFormBoundaryTEeQZVW5hNSWtIqS--
我尝试使用FileReader 将所选文件作为二进制字符串读取,并将内容写入请求正文而不是FormData,并且该请求适用于文本文件但不适用于XLSX 或PDF 数据被这样完全破坏了。
【问题讨论】:
-
@georgeawg 请再次访问该问题。我已经编辑了错误
-
只有当有 cmets 告诉我为什么所有这些反对票...:|
-
发送
Content-Type: multipart/form-data时的“垃圾线”是boundaries。您尝试了所有除了直接发送File对象的方法。
标签: angularjs openstack form-data angularjs-http openstack-swift