[英]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:
经过试验后,我最终有效的最终解决方案是:
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.