How to send the HTTP multipart/form-data from VB

mscproj
mscproj used Ask the Experts™
on
I have a servlet which can accept the follow HTTP Form File operation, and save the file into the server's File System

<FORM METHOD="POST" ACTION="http://localhost:8080/servlet/servletUpload" ENCTYPE="multipart/form-data">
   Select the file to upload  : <INPUT TYPE="FILE" NAME="FILE1" SIZE="25"><BR>
   <INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>

How can I write a VB Client that does the same thing? I got the VB as following, but it doesn't work at all.
I suspect I am sending a string, instead of the file object (sFile).

Any ideas?

Private Sub Command1_Click()
    Dim xmlHttp As New MSXML2.xmlHttp
       
    'Dim http As New WinHttp.WinHttpRequest
   
    With CommonDialog1
      .Flags = cdlOFNHideReadOnly Or cdlOFNFileMustExist
      .Filter = "All Files|*.*"
      .FileName = ""
      .ShowOpen
      sFile = .FileName
      sTitle = .FileTitle
    End With
   
    'MsgBox sFile
       
    xmlHttp.open "POST", "http://localhost:8080/servlet/servletUpload", False
    xmlHttp.setRequestHeader "ENCTYPE", "multipart/form-data"
   
    xmlHttp.send sFile
   
    If xmlHttp.Status = 200 Then
        MsgBox "Upload Successful!!"
    Else
        MsgBox "Upload Unsuccessful!!"
    End If
   
End Sub



Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
hi mscproj,

you have to send the binary data of the file, instead of the file name.

xmlHttp.send <Binary data>

Use Open statement to get the binary data of the file.
Author of the Year 2009

Commented:
Hi mscproj,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Save as PAQ -- No Refund.

mscproj, Please DO NOT accept THIS comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
Question placed in PAQ

Computer101
E-E Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial