Closed kaktus40 closed 1 year ago
It seems that upload.put.io is unreachable...
OK I changed my DNS server and upload.put.io is reachable. Now axios returns this error:
'Cannot parse form file: "file"\n'
These pieces of code worked for me:
import { uploadTorrent } from "../components/put";
import { ensureDirSync, removeSync } from "fs-extra";
import { resolve } from "path";
let tempPath = resolve(__dirname, "tempDownload");
ensureDirSync(tempPath);
export async function post(req, res) {
const files = req.files;
for (let item in files) {
const fileUploaded = files[item];
const chemin = resolve(tempPath, fileUploaded.name);
await fileUploaded.mv(chemin);
let temp = await uploadTorrent(chemin, fileUploaded.size);
removeSync(chemin);
}
return res.end(JSON.stringify({ status: "OK" }));
}
export async function uploadTorrent(
file: string,
size: number
): Promise<number> {
const form = new formData();
form.append("file", createReadStream(file), { knownLength: size });
form.append("parent_id", mainFolderId + "");
form.append("filename", "");
const formHeaders = form.getHeaders();
const headers = {
...formHeaders,
"Content-Length": form.getLengthSync(),
"Content-Type": "multipart/form-data",
accept: "application/json",
Authorization: `Bearer ${putToken}`,
};
const temp = await axios({
url: "https://upload.put.io/v2/files/upload",
method: "POST",
data: form,
headers,
});
return temp.status;
}
thanks to mcdado
Hey @kaktus40 I will do necessary inspection and then make sure that method works as it should.
Thank you for the report & explanation.
should be fixed in v8.35.1
, sorry for the late response...
Hello, following PR15 and this filename should be optional for Files.Upload function. If I omit this parameter, I have an issue with FormData. When I configure the filename parameter with anything, axios indicate
error_message: 'getaddrinfo ENOTFOUND upload.put.io'
Any help?