Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upload media to WhatsApp cloud API
#3
(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;

Reply


Messages In This Thread
Upload media to WhatsApp cloud API - by Lior I - 12-18-2022, 10:24 AM
RE: Upload media to WhatsApp cloud API - by rlebeau - 12-19-2022, 06:43 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)