Is there anyone that has uploaded media to wordpress?
I am trying to do it with TSslHttpRest but haven't succeeded.
Here is the code i use
procedure TForm1.UploadImageToWordPress(const URL, Username, Password, FilePath: string);
var
HttpRest: TSslHttpRest;
ResponseCode: Integer;
ResponseText: string;
aFileStream:TFileStream;
begin
HttpRest := TSslHttpRest.Create(nil);
try
HttpRest.OnHttpRestProg := onSslHttpRestProg ;
HttpRest.ServerAuth := httpAuthBasic;
HttpRest.Username := Username;
HttpRest.Password := Password;
HttpRest.SslCliSecurity := sslCliSecTls13Only;
HttpRest.ExtraHeaders.Add('Content-Disposition: "attachment; filename=example.jpg"');
HttpRest.ExtraHeaders.Add('Content-Type: "image/jpeg"');
HttpRest.ExtraHeaders.Add('Accept: "*/*"');
HttpRest.ExtraHeaders.Add('Accept-Encoding: "gzip, deflate, br"');
HttpRest.ExtraHeaders.Add('Connection: "keep-alive"');
HttpRest.RestParams.AddItemFile('example.jpg', FilePath, 0);
HttpRest.HttpUploadStrat := HttpUploadNone;
ResponseCode := HttpRest.RestRequest(httpPOST, URL, False, '');
ResponseText := HttpRest.ResponseRaw;
ShowMessage('Response Code: ' + IntToStr(ResponseCode));
ShowMessage('Response Text: ' + ResponseText);
finally
HttpRest.Free;
end;
end;
No matter what i do i get a 500 error.
I have successfully uploaded with postman or curl.
Thank you all