0

我正在尝试通过我正在开发的 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”而不是文件的上传名称相关联?

任何帮助表示赞赏。

4

1 回答 1

1

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

  1. 创建没有图像文件的新列表。
  2. 从响应中获取新列表的 listing_id 值。
  3. 发布对资源的第二次调用 - ("listings/[YOUR NEW LISTING'S ID]/images")。将图像文件添加到此请求。我还添加了 rank 参数来控制图像的显示顺序。

希望这可以帮助。

于 2014-12-15T22:18:15.027 回答