node-oauth icon indicating copy to clipboard operation
node-oauth copied to clipboard

posting multipart form data with oauth

Open Tekrajs opened this issue 4 years ago • 3 comments

Hello, I am trying to upload image to etsy with this package. I did the following for performing the operation.

    ` public async post(path: string, params: any, content: any, type: any) {
    var url: string;
    url = this.buildUrl(path, params);

    if (!this.authToken || !this.authSecret)
        throw new Error("Invalid or missing Token or Secret");

    console.log(type)
    let response: any = await new Promise((resolve, reject) => {
        return this.oauth.post(url, this.authToken, this.authSecret, content, type || false, function (err: any, data: any, response: any) {
            if (err) {
                return reject(err);
            }

            return resolve({ res: response, data: data });
        });
    });

    if (!response)
        throw new Error("Invalid response for request performed, please try again");

    return await this.handleResponse(response.res, response.data);

};`

the content passed to oauth.post is { name: __dirname + '/images/article-3.png', mime: 'image/jpeg', postname: 'article-3' }

Since the content type of content is not string and in library i saw this code

if ( typeof post_body != "string" && !Buffer.isBuffer(post_body) ) { post_content_type= "application/x-www-form-urlencoded" extra_params= post_body; post_body= null; }

my post content type is always application/x-www-form-urlencoded and i always get oauth_problem=signature_invalid problem. Can any one please provide me a sample code to upload a file with this oauth library to any api. Thanks.

Tekrajs avatar May 31 '20 18:05 Tekrajs

@Tekrajs did you figure this out? I'm trying to do the same thing.

jmgunter avatar Jun 11 '20 00:06 jmgunter

I'm dealing with the same problem.

oguzhanbulut avatar Aug 12 '20 09:08 oguzhanbulut

could somebody do it three years later?

patrickkmatias avatar Dec 15 '23 14:12 patrickkmatias