-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
As per title. I fixed this for my own use (although files still don't work obviously) and figured I should post it. Simplified the formatting a little as well.
(function(w){
if (w.FormData)
return;
function FormData(){
this.fake = true;
this.boundary = '--------FormData' + Math.random();
this._fields = [];
}
FormData.prototype.append = function(key, value){
this._fields.push([key, value]);
}
FormData.prototype.toString = function(){
var boundary = this.boundary;
var body = '';
for(var i = 0; i < this._fields.length; i++){
if (this._fields[i][1].name) {
var file = this._fields[i][1];
body += 'Content-Disposition: form-data; name="'+ this._fields[i][0] + '"; filename="' + file.name + '"\r\n';
body += 'Content-Type: ' + file.type + '\r\n\r\n';
body += file.getAsBinary() + '\r\n';
}
else{
body += '--' + boundary + '\r\n';
body += 'Content-Disposition: form-data; name="' + this._fields[i][0] + '";\r\n\r\n';
body += this._fields[i][1] + '\r\n';
}
};
body += '--' + boundary + '--';
return body;
}
w.FormData = FormData;
})(window);Metadata
Metadata
Assignees
Labels
No labels