我使用FileUploader UI5元素使用XMLHttpRequest(POST操作)上传文件,下面是我的代码片段 -
var input = document.querySelector('input[type="file"]');
var data = new FormData();
data.append("files", input.files[0]);
var xhr = new XMLHttpRequest();
xhr.open("POST","https://URL");
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.setRequestHeader("apikey", "XXXXXXXXXXXXXXXXX");
xhr.setRequestHeader("accept", "application/json");
xhr.send(data);
但在推送请求时,我的情况低于异常。不知道为什么我的帖子操作失败了,任何帮助都会受到赞赏。
错误说明 - 此服务至少需要1个文件。请将您的文件放入POST请求的files
字段"
这是请求标头和有效负载的样子 -
Request Header -
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
apikey:RGIukzqxB0GWhRaMMcCTmYGHnEWgk5qI
Connection:keep-alive
Content-Length:15
Content-Type:text/plain;charset=UTF-8
Host:sandbox.api.sap.com
Origin:https://webidetesting2532276-be010f3f7.dispatcher.us1.hana.ondemand.com
Referer:https://webidetesting2532276-be010f3f7.dispatcher.us1.hana.ondemand.com/extended_runnable_file.html?hc_orionpath=%2Fbe010f3f7%24S0015741697-OrionContent%2Fsap.ui.unified.sample.FileUploaderComplex&origional-url=index.html&sap-ui-appCacheBuster=&sap-ui-xx-componentPreload=off
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Request Payload -
[object Object]
答案 0 :(得分:1)
您已明确设置Content-Type,但它缺少MIME边界参数。完全省略标题并允许XHR从FromData对象推断出Content-Type。