for the file upload should be modify, so I try to combine the upload string by hand:
function submitdata(){
//var data = new FormData();
var sb="";
var BOUNDARY = "-------------------------4827543632391";
sb+="--"+BOUNDARY;
sb+="\r\n";
sb+="Content-Disposition: form-data; name=\"fileinput\" filename=\"004.jpg\" \r\n";
sb+="Content-Type: image/jpeg\r\n\r\n";
.....
var reader = new FileReader();
reader.readAsBinaryString(data);
//fd.append("blob", sb);
reader.onload = function(e){
sb+=this.result;
sb+="\r\n--" + BOUNDARY + "--\r\n";
var datasubmit="Content-Type:multipart/form-data; boundary="+BOUNDARY+"\n";
datasubmit+="Content-Length: "+eval(sb.length)+ "\r\n\r\n";
var xhr = new XMLHttpRequest();
xhr.open("POST", "addimages");
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.overrideMimeType('multipart/form-data');
xhr.sendAsBinary(datasubmit+sb);
}
}
every time the submit data body is:
Content-Type:multipart/form-data; boundary=-------------------------4827543632391
Content-Length: 283111
I want to put above part to heard not body!!!
---------------------------4827543632391
Content-Disposition: form-data; name="fileinput" filename="004.jpg"
Content-Type: image/jpeg
ÿØÿà�JFIF������ÿÛ�C� %# , #&')*)-0-(0%()(ÿÛ�C (((((((((((((((((((((((((((((((((((((((((((((((((((ÿÀ�@m"�ÿÄ����������� ÿÄ�µ���}�!1AQa"q2¡#B±ÁRÑð$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ�������� ÿÄ�µ��w�!1AQaq"2B¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz....
what I want is:
Request Headers From Upload Stream
Content-Length: 283122
Content-Type: multipart/form-data;boundary=---------------------------23281168279961
I just do not know my
Content-Type:multipart/form-data; …… to the header part of the Stream Form
can anyone give me an example of http package with “Content-Type:multipart/form-data;..” with the head? Or tell me how to write java-script to put the Content-Type: to head part.
I tried xhr.setRequestHeader(), it write the httphearder but not the Upload Stream header.
I may be misunderstanding, but you need to create new headers the xhr.setRequestHeader() method call.
As you’re doing it (and seeing) you’re just prepending material to the body. The setRequestHeader() method (taking the header name and content as two arguments) will create new headers to be sent. Note that you can create as many headers as you need by calling the method multiple times.
Hope this helps.