Fairly straight forward. I tried it with JQuery as you did, but couldn't accomplish it. So I went ahead and build my own XHR implementation that will send a custom multipart body to the server.
1) Initialize your XHR
2) Build the multipart body together
3) Send it
var xhr = new XMLHttpRequest();
...
xhr.open("POST", url, true);
var boundary = '------multipartformboundary' + (new Date).getTime(),
dashdash = '--',
crlf = '
',
This is were the magic happens. You build your own "body" for the transmission and put the image data as a normal variable with name into the body:
content = dashdash+boundary+crlf+'Content-Disposition: form-data; name="NAMEOFVARIABLEINPHP";"'+crlf+crlf+VARIABLEWITHBASE64IMAGE+crlf+dashdash+boundary+dashdash+crlf;
Then just send it of:
xhr.setRequestHeader("Content-type", "multipart/form-data; boundary="+boundary);
xhr.setRequestHeader("Content-length", content.length);
xhr.setRequestHeader("Connection", "close");
// execute
xhr.send(content);
If you use PHP, you have a new variable in your $_POST containing the base64 encoded string. This will prevent that the browser is breaking the string into 72 chars/line and stripping out the +'s and other special chars.
Hope that helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…