Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

POST binary file to HTTP with inet

Status
Not open for further replies.

Kasper

Programmer
Mar 12, 2001
3
US
I am trying to POST a binary file to a web form

Code:
<FORM ENCTYPE=&quot;multipart/form-data&quot; method=&quot;POST&quot; action=&quot;act_upfile&quot;>
<INPUT TYPE=FILE NAME=&quot;filename&quot;>
<INPUT TYPE=SUBMIT NAME=&quot;Upload&quot;>
</FORM>

I am using the following routine to do the POST:

Code:
Private Sub cmdUpload_Click()
Dim TempArray() As Byte
Dim Encoded() As Byte
Dim Message As String

If FileExists(txtFile.text) = False Then
MsgBox &quot;The file you have selected does not exist&quot;
End If

cmdUpload.Enabled = False
cmdBrowse.Enabled = False
txtFile.Enabled = False
lblStatus.Caption = &quot;Uploading file...&quot;
strHead = &quot;Content-Type: multipart/form-data; boundary=913114112&quot; & vbCrLf

LoadFile txtFile.text, pbBuffer1

ByteArrayToString pbBuffer1, ptContent
Base64.Str2ByteArray ptContent, TempArray
Base64.EncodeB64 TempArray, Encoded
Base64.Span 74, Encoded, TempArray

ByteArrayToString TempArray, ptContent

strFormData = &quot;-----------------------------913114112&quot; & vbNewLine
strFormData = strFormData & &quot;Content-Disposition: form-data; name=&quot;&quot;Bcmd&quot;&quot;&quot; & vbNewLine & vbNewLine & &quot;0&quot; & vbNewLine
strFormData = strFormData & &quot;-----------------------------913114112&quot; & vbNewLine
strFormData = strFormData & &quot;Content-Disposition: form-data; name=&quot;&quot;SUBMIT&quot;&quot;&quot; & vbNewLine & vbNewLine
strFormData = strFormData & &quot;Upload&quot; & vbNewLine
strFormData = strFormData & &quot;-----------------------------913114112&quot; & vbNewLine
strFormData = strFormData & &quot;Content-Disposition: form-data; &quot;
strFormData = strFormData & &quot;name=&quot;&quot;filename&quot;&quot;; filename=&quot;&quot;&quot; & txtFile.text & &quot;&quot;&quot;&quot; & vbNewLine
strFormData = strFormData & &quot;Content-Transfer-Encoding: BASE64&quot; & vbNewLine
strFormData = strFormData & &quot;Content-Type: multipart/form-data&quot; & vbNewLine & vbNewLine & ptContent & vbNewLine
strFormData = strFormData & &quot;-----------------------------913114112--&quot;
strLen = Len(strFormData)
MsgBox strFormData

Inet.Execute txtIP.text & &quot;:&quot; & txtPort.text & &quot;/act_upfile&quot;, &quot;POST&quot;, strFormData, strHead

While Inet.StillExecuting
DoEvents
Wend
MsgBox &quot;The file was successfully uploaded&quot;, vbInformation, &quot;File Uploaded&quot;
cmdUpload.Enabled = True
cmdBrowse.Enabled = True
txtFile.Enabled = True
End Sub

right at the inet.Execute command, it dies with the following error:
Run-time error '35760'
Cannot coerce type

Please help!
 
Kasper

having looked at MSDN it says
>The URL property must contain at least a protocol and remote host name.

are you setting prefixing TCPIP.text with &quot;FTP//&quot; anywhere

just a thought

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thanks for responding mattKnight, but no.
This particular project HAS to use HTTP in a web form with the form tag being what i posted above:
(< FORM ENCTYPE=&quot;multipart/form-data&quot; method=&quot;POST&quot; action=&quot;act_upfile >)
No other access methods are available.
The file(s) must be uploaded through the existing form.

the variable txtIP.text is &quot;the variable txtPort.text is &quot;10000&quot;
so the full URL being posted to is
&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top