mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
File upload fix
This commit is contained in:
parent
0da1dab95d
commit
8730318741
4 changed files with 30 additions and 14 deletions
|
@ -149,7 +149,7 @@ function WriteFile(content: string, path: string): void {
|
|||
|
||||
function writeFileAsync(content: string, path: string): void {
|
||||
CreatePath(path)
|
||||
fs.writeFile(path, content, function(err) {
|
||||
fs.writeFile(path, content, function (err) {
|
||||
if (err) {
|
||||
logger.Log(
|
||||
'Error writing file: ' + path + ' (sync)',
|
||||
|
@ -184,6 +184,13 @@ function deleteFile(fname: string): Boolean {
|
|||
function uploadFile(req: Request, path: string): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
if (!req.files) {
|
||||
logger.Log(
|
||||
`Unable to upload file, req.files is undefined`,
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
return
|
||||
}
|
||||
const file = req.files.file
|
||||
// FIXME: Object.keys(req.files).forEach((file) => { saveFile() })
|
||||
logger.Log('Uploading: ' + file.name, logger.GetColor('blue'))
|
||||
|
@ -217,7 +224,10 @@ function uploadFile(req: Request, path: string): Promise<any> {
|
|||
}
|
||||
})
|
||||
} catch (err) {
|
||||
logger.Log(`Unable to upload file!`, logger.GetColor('redbg'))
|
||||
logger.Log(
|
||||
`Unable to upload file, error on stderr`,
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.error(err)
|
||||
reject(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue