Binary Image Upload with Autoit

HTTP POST Binary Image File Upload with Autoit

C05348A3-9AB8-42C9-A6E0-81DB3AC59FEB
           

AutoIT Code Sample - Using an HTTP POST request to upload any file (JPEG/JPG/PNG/PDF/etc.) to a web service.

;===============================================================================
; Description:		HTTP Binary Image File Upload
; Author(s):		Videre Research, LLC - http://videreresearch.com
;===============================================================================

$sFilePath = @ScriptDir & '\myImage.jpeg' 
Local $sFile = FileOpen($sFilePath, 16)
If $sFile = -1 Then
	MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
EndIf
$sFileRead = BinaryToString(FileRead($sFile))
FileClose($sFile)

$sBoundary = "mymultipartboundary" 

$sPD = '--' & $sBoundary & @CRLF & _
		'Content-Type: application/json; charset=UTF-8' & @CRLF & @CRLF & _
		'{ "text": "JSON Text }' & @CRLF & _
		'--' & $sBoundary & @CRLF & _
		'Content-Type: image/jpeg' & @CRLF & _
		'Content-Transfer-Encoding: binary' & @CRLF & @CRLF & _
		$sFileRead & @CRLF & '--' & $sBoundary & '--' & @CRLF

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "http://www.yourservice.com/aaa", False)
$oHTTP.SetRequestHeader("Content-Type", 'multipart/related; boundary="' & $sBoundary & '"')
$oHTTP.Send(StringToBinary($sPD))
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

ConsoleWrite($oStatusCode & @CRLF)
ConsoleWrite($oReceived)
Posted Comments: 0