curl http://www.google.com/searchbyimage/upload -F "[email protected]"
Code I've tried:
Spoiler
Edit: I got it working:
Code: Select all
; Upload image to Google Images
; (Tested on AHK A32)
#NoEnv
#Include <HTTPRequest> ; http://www.autohotkey.com/board/topic/67989-func-httprequest-for-web-apis-ahk-b-ahk-lunicodex64/
ImagePath := "smile.gif"
FileRead, pack, *c %ImagePath%
FileGetSize, size, %ImagePath%
SplitPath, ImagePath, ImageFileName
Boundary := "b03f7ef85666"
CRLF := "`r`n"
DW := "UInt"
ptr := (A_PtrSize = "") ? DW : "Ptr"
; For AHK ANSI ONLY. To insert binary data into a string (such as multipart data).
VarSetCapacity( data, size + 500, 1 ) ; create a string of nonzero bytes longer than the binary data.
; Fill the multipart data with plain text, using the nonzero bytes as a placeholder for the binary data.
data := "------------------------------" Boundary CRLF
. "Content-Disposition: form-data; name=""encoded_image""; filename=""" . ImageFileName . """" CRLF
. "Content-Type: image/gif" CRLF CRLF
. SubStr( data, 1, size ) CRLF
. "------------------------------" Boundary "--" CRLF
; Calculate the offset at which the placeholder begins
offset := StrLen( data ) - size - StrLen( CRLF "------------------------------" Boundary "--" CRLF )
; Use the total size of the multipart data as the content length
headers := "Accept: */*`n"
. "Content-Length: " StrLen( data ) "`n"
. "Expect: 100-continue`n"
. "User-Agent: Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.15`n"
. "Content-Type: multipart/form-data; boundary=----------------------------" Boundary
; Copy the binary data into the string, overwriting the placeholder bytes
DllCall( "RtlMoveMemory", Ptr, &data + offset, Ptr, &pack, DW, size )
url := "http://www.google.com/searchbyimage/upload"
HttpRequest(URL, InOutData := data, InOutHeader := headers, "+NO_AUTO_REDIRECT`n+Flag: INTERNET_FLAG_NO_COOKIES")
Run, % RegExReplace(InOutHeader, "^.*Location: ([^\r\n]+).*$", "$1")
Return
- How to work with AHK Unicode?
- How to work using WinHttp.WinHttpRequest.5.1? I've tried it, the binary data disappeared.