Ask a questionAsk a question
 

QuestionJScript (AJAX) problem w sending multipart binary data

  • Thursday, July 30, 2009 12:31 PMTomáš Skála Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi, I have problem with sending multipart data via AJAX (XMLHttpRequest). Using similar code to this:


    var data1 = new ActiveXObject("Scripting.FileSystemObject" ).OpenTextFile(fileName1, 1).ReadAll();


    var boundary = "123098u19823j192j39123j1nini31n2" ;

    var xhr = new XMLHttpRequest();

    xhr.open("POST" , window.location.href, true );

    xhr.setRequestHeader("Content-Type" , "multipart/form-data; boundary=" + boundary);

               

    var request = "--" + boundary + "\r\n" ;

     

    request += 'Content-Disposition: form-data; name="fileBox1"; filename="' + fileName1 + '"\r\n' ;

    request += "Content-Type: application/octet-stream\r\n" ;

    request += "Content-Length: " + data1.length+"\r\n\r\n" ;

    request += data1 + "\r\n" ;

    request += "--" + boundary + "\r\n" ;

     

    request += 'Content-Disposition: form-data; name="textData"\r\n\r\n' ;

    request += "value\r\n" ;

     

    request+= "--" + boundary + "--" + "\r\n" ;

     

    xhr.setRequestHeader("Content-Length" , request.length);

    xhr.send(request);


    data1 value seems OK. request.length is OK. request.charAt() works perfectly. But xhr.send(request) will send only first 200b (from about 50000 total). IE8 (and propably other versions) sends raw data only until some specified char in stream found (#0 propably). So to server arrive only first 200 (or so) bytes. Using IIS5.1, but from FF3 and SendAsBinary this code works perfectly, so I thing its only IE specific issue.

    Is there some header or tag I'm missing?

All Replies

  • Saturday, November 07, 2009 8:18 PMmagnets Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi, I have problem with sending multipart data . . .
    Did you ever get a response?

    I have a version working successfully from a Visual Basic Express program.  It uses a "stream builder" to build the POST data stream that is sent to the server.

    However, I can not find anything similar in a jscript (.wsf) script.

    I tried just building a string using vbCrLf as "\r\n" but when the string is sent to the server using the .send method the server responds but never gets the multipart data.  The only thing I can figure is that I have to send a stream instead of a string.

    I just wish Microsoft would come up with one scripting language that does everything all the scripting languages do.  Since PHP is open source, Microsoft should run with it on their client machines.  Today the PHP implementation sucks on Windows boxes.  PHP is by far the best scripting language in the world as long as you stay away from the object-oriented c r a p.

    I hate switching back and forth between a half-dozen incomplete scripting languages.  It is very unproductive.

    Always Microsoft Problems