putdotio / putio-js

JavaScript SDK for interacting with the put.io API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Files.Upload with magnet file always results in 401

ptheofan opened this issue · comments

commented

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

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';
commented

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