Не мучайтесь.
FileSelectFile, filePath,,, Выберите файл изображения, Изображения (*.gif; *.tif; *.tiff; *.jpg; *.jpeg; *.png; *.bmp)
if !filePath
Return
oFile := FileOpen(filePath, "r", "cp0")
size := oFile.RawRead(buff, oFile.length())
oFile.Close()
base64 := CryptBinaryToStringBASE64(&buff, size, true)
obj := { api_key: "d45fd466-51e2-4701-8da8-04351c872236"
, detection_flags: "cropface,recognition,content,classifiers,basicpoints,propoints"
, file_base64: base64 }
JSON := json_fromobj(obj)
oWhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
oWhr.Open("POST", "https://www.betafaceapi.com/api/v2/media", false)
oWhr.SetRequestHeader("Content-Type", "application/json")
oWhr.SetRequestHeader("Content-Length", StrLen(JSON))
oWhr.SetRequestHeader("Connection", "keep-alive")
oWhr.SetRequestHeader("Referer", "https://betaface.com/demo.html")
oWhr.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
oWhr.Send(JSON)
MsgBox, % JSON := oWhr.ResponseText
CryptBinaryToStringBASE64(pData, bytes, NOCRLF = "")
{
static CRYPT_STRING_BASE64 := 1, CRYPT_STRING_NOCRLF := 0x40000000
CRYPT := CRYPT_STRING_BASE64 | (NOCRLF ? CRYPT_STRING_NOCRLF : 0)
DllCall("Crypt32\CryptBinaryToString", Ptr, pData, UInt, bytes, UInt, CRYPT, Ptr, 0, UIntP, chars)
VarSetCapacity(outData, chars << !!A_IsUnicode)
DllCall("Crypt32\CryptBinaryToString", Ptr, pData, UInt, bytes, UInt, CRYPT, Str, outData, UIntP, chars)
Return outData
}
json_fromobj(obj) {
if IsObject( obj ) {
isArray := true
for key in obj
if !( key = A_Index || isArray := false )
break
for k, v in obj
str .= ( A_Index = 1 ? "" : "," ) . ( isArray ? "" : json_fromobj(k) . ":" ) . json_fromobj(v)
return isArray ? "[" str "]" : "{" str "}"
}
else if !(obj*1 = "" || RegExMatch(obj, "\s"))
return obj
for k, v in [["\", "\\"], [A_Tab, "\t"], ["""", "\"""], ["/", "\/"], ["`n", "\n"], ["`r", "\r"], [Chr(12), "\f"], [Chr(08), "\b"]]
obj := StrReplace( obj, v[1], v[2] )
while RegexMatch( obj, "[^\x20-\x7e]", key ) {
str := Asc( key )
val := "\u" . Chr( ( ( str >> 12 ) & 15 ) + ( ( ( str >> 12 ) & 15 ) < 10 ? 48 : 55 ) )
. Chr( ( ( str >> 8 ) & 15 ) + ( ( ( str >> 8 ) & 15 ) < 10 ? 48 : 55 ) )
. Chr( ( ( str >> 4 ) & 15 ) + ( ( ( str >> 4 ) & 15 ) < 10 ? 48 : 55 ) )
. Chr( ( str & 15 ) + ( ( str & 15 ) < 10 ? 48 : 55 ) )
obj := StrReplace(obj, key, val)
}
Return """" obj """"
}
Там, правда, есть значение ключа — api_key: "d45fd466-51e2-4701-8da8-04351c872236" — не уверен, что оно постоянное.