5.- Upload image file to PC.
p119B_WiFiAutoit_Archivo.aia (92.0 KB)
Two examples:
a) Copy foto5.png from the asset to the ASD.
Convert it to Base64 using an extension.
Upload the string to the PC
b) Take Picture with cam.
Convert Picture to Base64 using an extension.
Upload the string to the PC.
The Autoit code receives the string, decodes the Base64 and saves it in the imagen1.png file, in the same directory as the script.
archivo.au3
#include "TCPServer.au3"
_TCPServer_OnReceive("received")
_TCPServer_DebugMode(True)
_TCPServer_SetMaxClients(10)
_TCPServer_Start(8081)
Func received($iSocket, $sIP, $sData, $sPar)
Sleep(100)
$BASE64_DATA = $sData
$BASE64_DATA = StringReplace ($BASE64_DATA, @CR, "")
$BASE64_DATA = StringReplace ($BASE64_DATA, @LF, "")
$base64_code = StringSplit($BASE64_DATA, "gzip", 1)
$BASE64_DATA =$base64_code[2]
Local $hFile = 0
$sImageName = "imagen1.png"
$hFile=FileOpen($sImageName, 18)
FileWrite($hFile, _Encoding_Base64Decode($BASE64_DATA))
FileClose($hFile)
_TCPServer_Send($iSocket, "HTTP/1.0 200 OK" & @CRLF & _
"Content-Type: text/html" & @CRLF & @CRLF & _
"Recibido.")
_TCPServer_Close($iSocket)
EndFunc ;==>received
While 1
Sleep(100)
WEnd
Func _Encoding_Base64Decode($sData)
Local $struct = DllStructCreate("int")
$a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
"str", $sData, _
"int", 0, _
"int", 1, _
"ptr", 0, _
"ptr", DllStructGetPtr($struct, 1), _
"ptr", 0, _
"ptr", 0)
If @error Or Not $a_Call[0] Then
Return SetError(1, 0, "") ; error calculating the length of the buffer needed
EndIf
Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")
$a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
"str", $sData, _
"int", 0, _
"int", 1, _
"ptr", DllStructGetPtr($a), _
"ptr", DllStructGetPtr($struct, 1), _
"ptr", 0, _
"ptr", 0)
If @error Or Not $a_Call[0] Then
Return SetError(2, 0, "") ; error decoding
EndIf
Return BinaryToString(DllStructGetData($a, 1))
EndFunc ;==>_Encoding_Base64Decode