
Untitled
By: a guest on
Jun 23rd, 2012 | syntax:
JavaScript | size: 1.18 KB | hits: 26 | expires: Never
uploadPickedFile_Chrome: function(inSender, inValue) {
try {
var formData = new FormData(inSender.$.form.getNode());
var headers = false;
if (SOME CONDITION THAT WILL REQUIRE HEADERS) {
headers = true;
}
// sample extra form data
formData.append('key', value);
var xhr = new XMLHttpRequest();
xhr.open('POST', PATH, true);
if (headers === true) {
var reqHeaders = {
header: 'value'
};
for (var header in reqHeaders) {
xhr.setRequestHeader(header, reqHeaders[header]);
}
}
xhr.onreadystatechange = enyo.bind(this, this.checkChromeUpload, xhr);
xhr.send(formData);
} catch(e) {
this.log("ERROR!");
this.log(e);
}
this.$.uploaderFilePicker.close();
},
checkChromeUpload: function(xhr) {
if (xhr.readyState === 4 && xhr.status === 200) {
this.successfulUpload({}, {completed: true, responseString: xhr.responseText}, {});
} else if (xhr.status > 200) {
// it failed, handle with an error message, or re-do the upload (set a flag to do this only once and only on the PlayBook due to its XHR upload bug)
} else {
this.log(xhr.readyState, xhr.status);
}
},