putdotio / putio-js

JavaScript SDK for interacting with the put.io API.
MIT License
21 stars 2 forks source link

Files.Upload with magnet file always results in 401 #42

Closed ptheofan closed 1 year ago

ptheofan commented 2 years ago

https://github.com/putdotio/putio.js/blob/7a02cec49669759bf525c006f3b333d8770f4c8b/src/resources/Files/Files.ts#L327

as per axios it looks like the post request does not hit upload.put.io. Instead, it hits api.put.io

image

jchiotaka commented 2 years ago

I had the same issue. Another problem is that the oauth_token should be sent as a url parameter.

A workaround would be to post the file using fetch (or any other way you prefer) and include the token.

    const formData = new FormData();
    formData.append('file', fs.createReadStream(file));

    const response = await fetch(`https://upload.put.io/v2/files/upload?oauth_token=${this.api.token}`, {
      method: 'POST',
      body: formData,
    });

and import

import FormData from 'form-data';
import fs from 'fs';
import fetch from 'node-fetch';
altaywtf commented 1 year ago

should be fixed in v8.35.1, sorry for the late response...