简体   繁体   English

使用RestSharp通过Etsy API上传图像

[英]Using RestSharp to upload an image via Etsy API

I'm trying to add an image along with a new listing to my Etsy account through a web application that I'm developing. 我正在尝试通过正在开发的Web应用程序将图像以及新列表添加到我的Etsy帐户中。 Currently, I am using: 目前,我正在使用:

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);

The listing is created correctly except there is no image. 清单正确创建,但没有图像。

I noticed that the etsyResponse has content containing information regarding the image uploaded (ie size, name, etc..) including a "tmp_name" created for the image. 我注意到etsyResponse的内容包含有关上载图像的信息(即大小,名称等),包括为该图像创建的“ tmp_name”。 Should I be associating the listing with the "tmp_name" from the etsyResponse instead of the uploaded name of the file? 我应该将列表与etsyResponse中的“ tmp_name”关联,而不是与文件的上载名称关联吗?

Any help is appreciated. 任何帮助表示赞赏。

I actually just had the exact same problem. 我实际上只是遇到了完全相同的问题。 I'm using a C# server side handler with RestSharp POSTing a new listing with image data from an HttpPostedFile instance. 我在RestSharp上使用C#服务器端处理程序,以HttpPostedFile实例中的图像数据发布新列表。 The draft listings were created just fine, but without any image. 清单草稿创建得很好,但是没有任何图像。 Like you mentioned, I saw the tmp_name and errors values which seemed to suggest the image was created. 就像您提到的那样,我看到了tmp_name和errors值,这些值似乎表明已创建映像。 After experimenting, my final solution which has worked just fine is to: 经过试验后,我最终有效的最终解决方案是:

  1. Create the new listing without the image file. 创建没有图像文件的新列表。
  2. Grab the new listing's listing_id value from the response. 从响应中获取新列表的listing_id值。
  3. POST a second call to the resource - ("listings/[YOUR NEW LISTING'S ID]/images"). 向资源发出第二个呼叫-(“列表/ [您的新列表的ID] /图像”)。 Add the image file to this request. 将图像文件添加到此请求。 I also add the rank parameter to control the image's display sequence. 我还添加了rank参数来控制图像的显示顺序。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM