title: File updload in post form in VBS
body: <p>I want to automate via Visual Basic Script the uploading of files I have in an HTML form. </p>
  
  <p>I am trying to make a post on an html form where I have to upload a file. I have managed to make the http call with this code:</p>
  
  <pre><code>    sFile = sFolder &amp; "file.txt"
      sBoundary = "-ooo-"
      Set req = CreateObject("MSXML2.XMLHTTP")
      req.open "POST", SIGNurl, False
      req.setRequestHeader "Content-Type", "multipart/form-data; boundary=" + sBoundary 
  
      inByteArray = readBytes(sFile)
      base64Encoded = encodeBase64(inByteArray)
  
      request = request &amp; sBoundary &amp; vbCrLf
      request = request &amp; "Content-Disposition: form-data; name=file; filename=" &amp; sFile &amp; vbCrLf
      request = request &amp; "Content-Type: application/x-object" &amp; vbCrLf
      request = request &amp; base64Encoded &amp; vbCrLf
      request = request &amp; sBoundary &amp; vbCrLf
  
      req.setRequestHeader "Content-Length", Len(request)
      req.send request
      WScript.Echo req.responseText
      Set req = Nothing
  
  Private function readBytes(file)
    dim inStream
    ' ADODB stream object used
    set inStream = WScript.CreateObject("ADODB.Stream")
    ' open with no arguments makes the stream an empty container 
    inStream.Open
    inStream.type= 1
    inStream.LoadFromFile(file)
    readBytes = inStream.Read()
  end function
  
  Private function encodeBase64(bytes)
    dim DM, EL
    Set DM = CreateObject("Microsoft.XMLDOM")
    ' Create temporary node with Base64 data type
    Set EL = DM.createElement("tmp")
    EL.DataType = "bin.base64"
    ' Set bytes, get encoded String
    EL.NodeTypedValue = bytes
    encodeBase64 = EL.Text
  end function
  </code></pre>
  
  <p>I am getting a 400 Server error saying "Missing file content in upload". I am not sure what i am missing but something there must be wrong.</p>
  
  <p>Any help?</p>