-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] File upload without useTempFile
results in empty files
#118
Comments
Looks you are right. this tempFilePath allways has a value, probably it is a not best way for such check. I'm currently working on some changes for this module and they also will fix this issue. |
Awesome. ❤️ Let me know if there's anything I can assist you. As a workaround, I did this for now: const { name, data } = upload;
const toPath = path.join(uploadRoot, name);
upload.mv(toPath, uploadErr => {
if (uploadErr) {
return res.status(500).send(`Failed to upload ${name}.`);
}
const stream = fs.createWriteStream(toPath, { encoding: 'utf8' });
stream.once('open', () => {
stream.write(data, writeErr => {
if (writeErr) {
return res.status(500).send(`Failed to write content ${name}.`);
}
stream.close();
console.log(`File ${fs.existsSync(toPath) ? 'exists' : 'does NOT exist'} under ${toPath}.`);
if (fs.existsSync(toPath)) {
console.log(`Content of ${toPath}:`);
console.log(fs.readFileSync(toPath).toString());
}
})
});
}); |
Hi, @kittaakos , @richardgirges I've created some changes which will fix that issue. please see PR #119 |
@RomanBurunkov, I have checked out the |
@kittaakos Fixed some typos and erros. All tests passed ;) |
Nice. I can confirm, my example from above works with your changes 🎉 |
v1.1.1-alpha.3 released on NPM: https://github.com/richardgirges/express-fileupload/releases/tag/v1.1.1-alpha.3 |
My files are created but the content is empty after calling
mv
on theUploadedFile
. I am using"express-fileupload": "^1.1.1-alpha.2"
.The files I am trying to upload.
The buffer-based move logic never runs because the
!options.tempFilePath
isfalse
although I set neither theuseTempFiles
nor thetempFileDir
properties in the options. Perhaps this change is related. If in debug mode, I explicitly unset theoptions.tempFilePath
and themoveFromBuffer
is called, then it works as expected.Thank you!
The text was updated successfully, but these errors were encountered: