add pack upload file

master
ogomez-at-wiris 2022-02-27 07:40:05 +01:00
parent 5dabcc4649
commit 434a54b038
1 changed files with 22 additions and 2 deletions

View File

@ -1,9 +1,29 @@
import { Request, Response, NextFunction, response } from "express";
import os from "os";
const uploadsFolder = `${os.homedir()}/beatloads`;
export default class PackUploader {
public static uploadPack = async (
req: Request,
req: any,
res: Response,
next: NextFunction
) => {};
) => {
let packName;
if (!req.files || Object.keys(req.files).length === 0) {
return res.status(400).send("No files were uploaded.");
}
try {
const packFile = req.files.pack;
packName = req.files.pack.name;
const path = `${uploadsFolder}/${packName}`;
await packFile.mv(path);
} catch (error) {
return res.status(500).send(error);
}
return res.status(200).send("File uploaded!");
};
}