Created
January 10, 2012 21:47
-
-
Save mrdoob/1591401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MultipartForm = function () { | |
var boundary = '------------------------------' + Date.now(), string = '--' + boundary + '\r\n'; | |
this.addVariable = function ( name, value ) { | |
string += 'Content-Disposition: form-data; name="' + name + '"\r\n'; | |
string += 'Content-Type: text/plain\r\n'; | |
string += '\r\n' + value + '\r\n'; | |
string += '--' + boundary + '\r\n'; | |
}; | |
this.addFile = function ( name, filename, filetype, data ) { | |
string += 'Content-Disposition: form-data; name="' + name + '"; filename="' + filename + '"\r\n'; | |
string += 'Content-Type: ' + filetype + '\r\n'; | |
string += '\r\n' + data + '\r\n'; | |
string += '--' + boundary + '\r\n'; | |
}; | |
this.getBoundary = function () { | |
return boundary; | |
}; | |
this.getString = function () { | |
return string; | |
}; | |
this.getBuffer = function () { | |
return new Uint8Array( Array.prototype.map.call( string, function ( x ) { return x.charCodeAt( 0 ) & 0xff; } ) ).buffer; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment