xhr.send(文件)不会将其作为多部分发布 [英] xhr.send(file) doesn't post it as multipart
问题描述
试过这样做: http:// kaply.com/weblog/2010/05/20/post-multipart-form-xhr/ b
$ b
但是,不能真正将字符串与文件内容混合发送()期间。
任何解决方法?
xhr.send(FormData)
,它会创建一个 multipart / form-data
请求,允许附加文件,和任意形式的数据。 var formData = new FormData();
formData.append(file.name,file);
var xhr = new XMLHttpRequest();
xhr.open('POST','/ upload',true);
xhr.onload = function(e){...};
xhr.send(formData); // multipart / form-data
请参阅 http://www.html5rocks.com/en/tutorials/file/xhr2/#toc-send-formdata
On Firefox 3.6 and Chrome, using xhr.send(file) just puts the raw contents into the body of the request and it is not a true multipart/form-data upload.
Tried doing this: http://kaply.com/weblog/2010/05/20/post-multipart-form-xhr/
But, can't really mix string with File contents during send().
Any workarounds?
xhr.sendAsBinary()
is non-standard. Instead, use xhr.send(FormData)
, which does create a multipart/form-data
request, allows appending files, and arbitrary form data.
var formData = new FormData();
formData.append(file.name, file);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.onload = function(e) { ... };
xhr.send(formData); // multipart/form-data
See http://www.html5rocks.com/en/tutorials/file/xhr2/#toc-send-formdata
这篇关于xhr.send(文件)不会将其作为多部分发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!