Jump to content

Multipart file uploading using winhttp.winhttprequest.5.1


Recommended Posts

i'm trying to upload some image files to server using post method.

i got NullPointerException error from server that is implemented on spring framework.

the server didn't receive the capturedImageFile field.

please let me know what problem and solution are.
 
here is my piece of code

Local $boundary = "------" & _TimeToTicks(@HOUR, @MIN, @SEC)
Local $contentDisposition = "form-data; name=""capturedImageFile""; filename=""" & $sFileName & '"'
Local $contentType = "multipart/form-data"
Local $origin = "null"

$http = ObjCreate("winhttp.winhttprequest.5.1")
$http.Open("POST", $sUrl, False)
$http.SetRequestHeader("Content-Type", $contentType & "; boundary=" & $boundary)

Local $hFile = FileOpen($sFileName, 16)
Local $postData = $boundary & @LF
$postData &= 'Content-Disposition: form-data; name="capturedImageFile"; filename="' & $sFileName & '"' & @LF
$postData &= "Content-Type: " & "image/bmp;" & @LF
$postData &= @LF & FileRead($hFile) & @LF
$postData &=  $boundary & "--"
$http.Send($postData)
    
FileClose($hFile)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...