Jump to content
Sign in to follow this  
George Bairaktaris

Wordpress upload media

Recommended Posts

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

 

 

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×