Granga / etsy-ts

Etsy API wrapper written in typescript
https://www.npmjs.com/package/etsy-ts
MIT License
37 stars 5 forks source link

Unable to upload Images #9

Closed haoxiaogang0919 closed 3 years ago

haoxiaogang0919 commented 3 years ago

"Content-Type":"multipart/form-data"

Granga commented 3 years ago

Hi @Wulaowu. Here's a solution:

  1. Install form-data package if you are making this request from node.
  2. Use the following code:
    
    let formData = new FormData();
    formData.append("listing_id", "<listing_id>");
    formData.append("image", fs.createReadStream("<path_to_image>"));

let image = (await client.ListingImage.uploadListingImage( formData as any, { axiosConfig: { headers: formData.getHeaders() }, token: token } )).data.results[0];



*Unfortunately, we have to cast parameters `as any`, therefore losing strong typing advantages. 
This can be considered in the API wrapper, but I say let's wait for API v3 and see if it's' worth the effort.*
Granga commented 3 years ago

Make sure you provide both correct listing_id and path_to_image. I've put placeholders for those values in the above code.

haoxiaogang0919 commented 3 years ago

Already, I forgot to upload listing_id just now. I am waiting for v3 to appear