procedure APIAddImage(FileName: string);
begin
try
ResponseStream := TStringStream.Create('');
SourceStream := TStringStream.Create('');
try
URL := 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/add?access_token=' + AccessToken;
imagepath := fImageList[i];
image := Base64E(imagepath);
brief := FileName;
tags := Tag1 + ',' + Tag2;
SourceStream.WriteString('image=' + httpencode(image) + '&brief=' + httpencode(brief) + '&tags=' + httpencode(tags));
HttpClient.Request.CustomHeaders.Values['Content-Type'] := 'application/x-www-form-urlencoded';
HttpClient.Post(URL, SourceStream, ResponseStream);
JO := SO(ResponseStream.DataString);
if (JO['error_code'] = nil) or (JO.S['error_code'] = '216681') then
begin
log_id := JO.S['log_id'];
cont_sign := JO.S['cont_sign'];
InsertImageData(JO.S['log_id'], JO.S['cont_sign']);
ImagesStr := ResponseStream.DataString;
end
else
begin
Logs(JO.S['log_id'] + '$' + JO.S['error_code'] + '&' + JO.S['cont_sign'] + '&' + JO.S['error_msg']);
ImagesStr := ResponseStream.DataString;
end;
except
on e: Exception do
begin
Logs('error--' + URL + '--' + imagepath);
ShowMessage(e.Message);
end;
end;
finally
ResponseStream.Free;
SourceStream.Free;
end;
end;