Reputation: 4798
Recently I have implemented image upload to Amazon S3 from javascript in browser. I have focused to FireFox, Chrome and IE only.
At the end I have not managed to implement it for IE - any version(even 10).
The use case was something like this:
The another important thing is that browsers' location protocol is https.
Problems: I have run into several problems, mostly on IE.
IE 10 can do that stuff (1 and 2) but has an issue with xhr.open("POST",url,true) - it crashes when url starts with http:// (the browser calls it from https://something.com/more/stuff)
3.1. If browser is on http it works.
3.2. if POST request is called for url that starts with https:// it doesn't crash but it fails uploading 3.2.1. The same as 3.2 is happening on the FireFox
Not acceptable solutions:
It would be really, really good if the solution would support older browsers, it would be very good if it supports IE9+, and ok if supports just IE10. Of course FF and Chrome should work with it also.
Here is a part of code that works, but have an issue (problem 3):
function sendFile(putFields){
var xhr = new getXHRObject(); // returns new XMLHttpRequest object.
var url = 'http://'+putFields.bucket+"."+putFields.host+"/";
xhr.onreadystatechange=function(){
if (http.readyState==4&&null!=http.status&&(http.status==200||http.status==201
||http.status==202||http.status==204||http.status==205||http.status==0)){
alert('success!');
}else if (http.readyState==4){
alert('fail ');
}
}
var params={
'acl':""+putFields.acl,
'key':""+putFields.key,
'Content-Type':putFields.contentType,
'AWSAccessKeyId':putFields.awsAccessKeyId,
'signature':putFields.signature,//encodeURIComponent()
'policy':""+putFields.policy,
'file':aFile
};
var fData = new FormData();
for (var p in params)
fData.append(p,params[p]);
xhr.open("POST", postUrl, true); // IE crashes here when https-->http is the case
setTimeout(function(){ xhr.send(fData);}, 100);
}
I am trying to find solution for this for some time now but with no real success, please help!
Upvotes: 0
Views: 1628
Reputation: 254
If any one still gets this error, I found that adding 'contentType' fixed it
$('.uploadAssets').ajaxForm( {
dataType: 'json',
contentType: 'application/json; charset=utf-8',//added this line and problem solved
beforeSend: beforeuploadAssetsPostForm,
success: uploadAssetsFormResponse,
error: uploadAssetsError
});
Upvotes: 1