none
Jscript Sent Post request with a zip file

    Question

  • Hi,

    I try to send a zip file in a POST request with a JScript. My zip is in the same folder of the .js. My problem is to read the zip and send it.

    function builtRequest () {
            boundary = "---------------------------8d821258453695";
            var req = new  ActiveXObject("WinHttp.WinHttpRequest.5.1");
            req.Open("POST", "url/traitement.php");
    	req.setRequestHeader("Content-Type","multipart/form-data; charset=UTF-8; boundary="+boundary);
    	req.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");			
    	req.setRequestHeader("Accept-Encoding","gzip,deflate");
    	//req.setRequestHeader("Accept-Charset","UTF-8, US-ASCII");
    	req.setRequestHeader("Content-Transfer-Encoding","binary");	
    	req.Send (builtCont(boundary));
    	return req.ResponseText;
    }
    
    function builtContent (boundary) {
    
            var strFile = "";
            strFile = getFileToStr ("My.zip");
            vbCrLf = "\n";	
    	var PreFile = '--'+boundary+vbCrLf+'Content-Disposition: form-data; name="file"; filename="My.zip"'+vbCrLf+'Content-Type: application/x-zip-compressed'+vbCrLf+vbCrLf;
    	var PostFile = vbCrLf+'--'+boundary+"--"+vbCrLf;
    
    	
    	var Content = PreFile+strFile+PostFile;
    
    	return Content;
    
    }
    
    function getFileToStr (pathFile) {
    // For read the Zip I try :
    
            var fso	= new ActiveXObject("Scripting.FileSystemObject");
    	var lgf	= fso.OpenTextFile(pathFile);
    	strFile	=	lgf.ReadAll();
    	lgf.Close();	
    	return strFile;
    
    /* But the $FILE have a  3 error:
      ["file"]=>
      array(5) {
        ["name"]=>
        string(18) "My.zip"
        ["type"]=>
        string(0) ""
        ["tmp_name"]=>
        string(0) ""
        ["error"]=>
        int(3)
        ["size"]=>
        int(0)
      }
    } 
    */
    
    // And I try :	
    
            var Stream= new ActiveXObject("ADODB.Stream"); 
    	Stream.Type = 1;
    	Stream.Open;
    	Stream.LoadFromFile (pathFile);
    	strFile = Stream.Read(); 
    	Stream.Close;
    	return strFile;
    
    /* But My $FILE is empty :
    
      ["file"]=>
      array(5) {
        ["name"]=>
        string(18) "My.zip"
        ["type"]=>
        string(28) "application/x-zip-compressed"
        ["tmp_name"]=>
        string(14) "/tmp/phpgmihiK"
        ["error"]=>
        int(0)
        ["size"]=>
        int(0)
      } 
    ( bucause the return is empty strFile)
    
    */
    
    
    
    }
    
    
    
    }
    
    
     

    So if you have an idea, thank you.


    • Edited by Linkenox Tuesday, May 15, 2012 2:24 PM
    Tuesday, May 15, 2012 2:24 PM

Answers

All replies

  • Hi Linkenox,

    Welcome to the MSDN forum.

    I will try to involve some senior engineers in your thread. Please wait for the response.

    Sorry for any inconvenience.

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, May 16, 2012 9:43 AM
  • Thanks,

    Now I have changed this function :

    function getFileToStr (pathFile) {

    var Stream= new ActiveXObject("ADODB.Stream");
        Stream.Type = 2;    
        Stream.CharSet = "iso-8859-1";    
        Stream.Open;
        Stream.LoadFromFile (pathFile);    
        strFile = Stream.readText();    
        Stream.Close;
        return strFile; }

    And now the "strFile" have the good encoding ANSI : iso-859-1.

    But i have always error 3 :

    UPLOAD_ERR_PARTIAL Value: 3; The uploaded file was only partially uploaded.

    Source : http://lu.php.net/manual/en/features.file-upload.errors.php

      ["file"]=>
      array(5) {
        ["name"]=>
        string(18) "My.zip"
        ["type"]=>
        string(0) ""
        ["tmp_name"]=>
        string(0) ""
        ["error"]=>
        int(3)
        ["size"]=>
        int(0)
      }

    thanks for your help



    • Edited by Linkenox Wednesday, May 16, 2012 9:59 AM
    Wednesday, May 16, 2012 9:52 AM
  • Problem solve with :

    http://wqweto.wordpress.com/

    • Marked as answer by Linkenox Wednesday, May 16, 2012 2:40 PM
    Wednesday, May 16, 2012 2:39 PM