开发者

Ajax upload file error with Google Chrome?

开发者 https://www.devze.com 2023-04-05 12:04 出处:网络
I\'m using noswfupload (ajax uploader) with my web application, and it work fine with Firefox and IE, but it\'s not working with Google开发者_如何学JAVA Chrome. I found an error which show that \"PHP

I'm using noswfupload (ajax uploader) with my web application, and it work fine with Firefox and IE, but it's not working with Google开发者_如何学JAVA Chrome. I found an error which show that "PHP Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0"

could anyone tell me how to solve this problem?


Not sure about your specific uploader, but:

This error is a problem with the way that your xhr request headers are set, and also your request data. Valid syntax ( from my chrome debug console ) looks like this:

request header:

Content-Type:multipart/form-data; boundary=----WebKitFormBoundarykEVXyg09HZBMzplL

request data:

------WebKitFormBoundarykEVXyg09HZBMzplL
Content-Disposition: form-data; name="foo_bar"

data:image/jpeg;base64,/9j/4AAQSkZJ
     [....]
pAkhCD/9k=
------WebKitFormBoundarykEVXyg09HZBMzplL--

You can see the http rfc here: http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html , it mentions the boundary syntax in the header....

You can manually change the header as in this answer: How to send multipart/form-data form content by ajax (no jquery)? , or you can try to solve it at a higher level.

The formData object can mimic those parameters too, (although it's not implemented in all browsers) ... https://developer.mozilla.org/en/DOM/XMLHttpRequest/FormData/Using_FormData_Objects

I had a problem with a jquery ajax call to a php file (with the same error) and solved it by ditching jquery and using formData and the raw httpxhrrequest.

0

精彩评论

暂无评论...
验证码 换一张
取 消