Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to upload Images #9

Closed
haoxiaogang0919 opened this issue Mar 10, 2021 · 3 comments
Closed

Unable to upload Images #9

haoxiaogang0919 opened this issue Mar 10, 2021 · 3 comments

Comments

@haoxiaogang0919
Copy link

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

@Granga
Copy link
Owner

Granga commented Mar 10, 2021

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<IListingImage>(
    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
Copy link
Owner

Granga commented Mar 10, 2021

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

@haoxiaogang0919
Copy link
Author

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

@Granga Granga closed this as completed Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants