如何使用 TRestClient 库从 Delphi (Rio) 应用程序将媒体项目上传到 WordPress [英] How to upload a media item to WordPress from Delphi (Rio) app using TRestClient library

查看:19
本文介绍了如何使用 TRestClient 库从 Delphi (Rio) 应用程序将媒体项目上传到 WordPress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 WordPress 开发的网站,其中包含一个模板,通过 WP 自己对 REST API 的支持启用内容管理,我们希望上传与照片相关联的内容.这个想法是上传照片,然后上传与上传的照片相关联的内容.我们上传照片的代码如下(使用Delphi发行版提供的库使用示例):

We have a WordPress developed site with a template that enables content management through WP's own support for REST API, and we want to upload content that has photos associated with it. The idea is to upload the photos, and then upload the content associating it with the uploaded photos. Our code for uploading photos is as follows (using the library usage example provided with the Delphi distribution):

procedure Tfrm_Main.btn_MediaClick(Sender: TObject);
var jpgFoto: TMemoryStream;
begin
  ResetRESTComponentsToDefaults;

  RESTClient.BaseURL := lbledt_BaseWProp.Text;
  RESTClient.Authenticator := HTTPBasic_DelphiPRAXiS;

  RESTRequest.Resource := 'media';

  HTTPBasic_DelphiPRAXiS.Username := lbledt_Usuario.Text;
  HTTPBasic_DelphiPRAXiS.Password := lbledt_Clave.Text;

  jpgFoto := TMemoryStream.Create;
  jpgFoto.LoadFromFile('t:\beautiful-blowball-dandelion-vector-background.jpg');
  jpgFoto.Position := 0;
  RESTRequest.AddBody(jpgFoto, TRESTContentType.ctIMAGE_JPEG);
  RESTRequest.Method := TRESTRequestMethod.rmPOST;

  RESTRequest.Execute;
  jpgFoto.Free;
end;

得到的响应如下:

{
    "code": "rest_upload_no_content_disposition",
    "message": "No se ha facilitado la disposición de contenido.",
    "data": {
        "status": 400
    }
}

我们还没有看到如何做到这一点的清晰示例,我们迷失在寻找解决方案的过程中.谢谢!

We have not seen a clear example of how to do it and we are lost in the search for a solution. Thank you!

推荐答案

尝试了很多替代方案...最后我尝试了 Indy TidHTTP 组件.它似乎工作正常!谢谢

Try a lot of alternatives... finally i am giving a try to Indy TidHTTP component. It seems to work fine! Thanks

这篇关于如何使用 TRestClient 库从 Delphi (Rio) 应用程序将媒体项目上传到 WordPress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆