(12-18-2022, 10:24 AM)Lior I Wrote: Can someone help me translate this WhatsApp curl example code to Delphi pascal?
...
I don't know how to translate the file parameter. It includes both path and file type attributes.
Code:-F 'file=@/local/path/file.jpg;type=image/jpeg'
If you read curl's documentation, you would see that the -F parameter is for sending an HTML webform in multipart/form-data format. Indy's TIdHTTP has an overloaded Post() method which takes a TIdMultipartFormDataStream as input, eg:
Code:
uses
..., IdMultipartFormDataStream;
var
PostData: TIdMultipartFormDataStream;
begin
PostData := TIdMultipartFormDataStream.Create;
try
PostData.AddFile('file', '/local/path/file.jpg', 'image/jpeg');
PostData.AddFormField('messaging_product', 'whatsapp');
IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ACCESS_TOKEN';
IdHTTP.Request.BasicAuthentication := False;
IdHTTP.Post('https://graph.facebook.com/v15.0/FROM_PHONE_NUMBER_ID/media', PostData);
finally
PostData.Free;
end;
end;
