使用RestSharp通过Etsy API上传图像

本文关键字:图像 API Etsy RestSharp 通过 使用 | 更新日期: 2023-09-27 18:33:30

我正在尝试通过我正在开发的Web应用程序将图像和新列表添加到我的Etsy帐户中。 目前,我正在使用:

RestRequest request = new RestRequest("listings", Method.POST);
request.AddFile("image", ReadToEnd(o.mainPhoto), "test.bmp", "image/bmp");
request.AddParameter("image", "test.bmp");
request.AddParameter("title", "This is a test");
request.AddParameter("description", "Test Description");
request.AddParameter("status", "draft");
request.AddParameter("quantity", "1");    
request.AddParameter("price", "5");
request.AddParameter("is_supply", "false");
request.AddParameter("category_id", "68887420");
request.AddParameter("when_made", "2013");
request.AddParameter("who_made", "i_did");
request.AddParameter("shipping_template_id", 5463224); 
var etsyResponse = restClient.Execute<EtsyListing>(request);

列表创建正确,但没有图像。

我注意到 etsyResponse 的内容包含有关上传图像的信息(即大小、名称等),包括为图像创建的"tmp_name"。 我是否应该将列表与 etsyResponse 中的"tmp_name"相关联,而不是上传的文件名称?

任何帮助,不胜感激。

使用RestSharp通过Etsy API上传图像

我实际上遇到了完全相同的问题。我正在使用带有 RestSharp 的 C# 服务器端处理程序,使用来自 HttpPostedFile 实例的图像数据发布新列表。列表草稿创建得很好,但没有任何图像。就像你提到的,我看到了tmp_name和错误值,这似乎表明图像已创建。经过实验,我的最终解决方案效果很好:

  1. 创建不带图片文件的新商品信息。
  2. 从响应中获取新列表的listing_id值。
  3. 发布对资源的第二次调用 - ("列表/[您的新列表的 ID]/图像")。将图像文件添加到此请求。我还添加了 rank 参数来控制图像的显示顺序。

希望这有帮助。