我有一个本地应用程序需要将视频/图像发送到我的服务器.我已经知道正常帖子可以正常工作但是当我尝试发送一个formData对象时,它似乎永远不会离开手机.这是我的代码.
// method = 'POST';
// body = new formData();
// body contains text data and image/video file
const post = (url, body, token, method) => {
let xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.setRequestHeader('Authorization', 'Bearer' + token);
xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=---------------------------7692764ac82');
xhr.send(body);
console.log(xhr);
return xhr.response;
}
Run Code Online (Sandbox Code Playgroud)
body是包含图像/视频的formData对象.在xhr在控制台日志中打印的对象中,_response包含"二进制FormData部分需要内容类型标题".但似乎我把它正确设置好了吗?
请帮助,还有其他类似的问题,但我已经没有想法了.我也试过使用fetch但没有成功.