【问题标题】:Using RestSharp to upload an image via Etsy API使用 RestSharp 通过 Etsy API 上传图片
【发布时间】:2015-09-16 13:04:05
【问题描述】:

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

感谢任何帮助。

【问题讨论】:

    标签: c# image oauth restsharp etsy


    【解决方案1】:

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

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

    希望这会有所帮助。

    【讨论】:

    • 所以没有办法同时上传图片和新listing??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 2022-07-26
    • 1970-01-01
    相关资源
    最近更新 更多