formidable handle no uploaded file errors










0














Everything is working as expected in my code except if the user has not uploaded a file it crashes my node app.



The error is arising at the fs.rename part, as there is nothing uploaded the app cant rename anything and causes the following:



Error:




EPERM: operation not permitted, rename 'C:UsersxxxAppDataLocalTempupload_0a145049089fa69e9df64f8d20abb362' -> 'C:UsersxxxDropboxAutomate NodeJSLogin_Register+Submit - 0.01data5be13231807fe33f14b2834asdS9m'




Im having difficulty searching for my err and how to handle that, If anyone can point me to some resources for how to handle formidable errors and how to stop the process of the user hasn't uploaded anything it would be fantastic.



It's not a production app or anything of the like its just me learning how to deal with multiple functions and a database at once.



router.post('/submit', userisSubbed, userhasTime, (req, res, next0) => 
var userId = req.user._id;
var username = req.user.email;
var isCompleted = 'No'
var jobNumber = generator.generate(
length: 5,
numbers: true
);
// Validate
const errors = req.validationErrors();

if (errors)
res.render('index',
errors: errors
);

else
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files)
var userPath = req.user._id
var dir = './data/' + userPath + '/' + jobNumber + '/';
if (!fs.existsSync(dir))
fs.mkdirSync(dir);

else

console.log("Directory already exist");


var oldpath = files.filetoupload.path;
var newpath = dir + files.filetoupload.name;
// copy the file to a new location
fs.rename(oldpath, newpath, function (err)
if (err) throw err;
console.log('renamed complete');
const newJob = new Job(
userId: userId,
username: username,
isCompleted: isCompleted,
filepath: newpath,
jobNumber: jobNumber,
);
Job.createJob(newJob, function(err, job)
if (err) throw err;
console.log(job);
);
req.flash('success_msg', 'Job Submitted...');
res.redirect('/')
);
);

);









share|improve this question























  • stackoverflow.com/questions/39293636/…
    – Suresh Prajapati
    Nov 12 '18 at 5:54










  • @SureshPrajapati At your current reputation score you can actually "vote to close as duplicate". So if you think something is a duplicate, then please just do so. Questions can always be reopened IF there is a compelling reason that it requires a different solution from the duplicate. I will say however that this question is not about npm install, so though there's a common "underlying cause" then it's not the same thing, and does not need random links in comments either.
    – Neil Lunn
    Nov 12 '18 at 6:01











  • @SureshPrajapati whilst the error is the same the cause is different, thanks for trying though
    – Phillip Lakis
    Nov 12 '18 at 6:15










  • @PhillipLakis did u try npm cache clean --force and npm install -g npm@latest ?
    – Suresh Prajapati
    Nov 12 '18 at 6:18










  • @SureshPrajapati my error is caused by my router.POST and the rename not happening, Did you read my entire post and not just the error? And yes i tried your npm but it doesnt solve the empty field of the router.post
    – Phillip Lakis
    Nov 12 '18 at 6:20
















0














Everything is working as expected in my code except if the user has not uploaded a file it crashes my node app.



The error is arising at the fs.rename part, as there is nothing uploaded the app cant rename anything and causes the following:



Error:




EPERM: operation not permitted, rename 'C:UsersxxxAppDataLocalTempupload_0a145049089fa69e9df64f8d20abb362' -> 'C:UsersxxxDropboxAutomate NodeJSLogin_Register+Submit - 0.01data5be13231807fe33f14b2834asdS9m'




Im having difficulty searching for my err and how to handle that, If anyone can point me to some resources for how to handle formidable errors and how to stop the process of the user hasn't uploaded anything it would be fantastic.



It's not a production app or anything of the like its just me learning how to deal with multiple functions and a database at once.



router.post('/submit', userisSubbed, userhasTime, (req, res, next0) => 
var userId = req.user._id;
var username = req.user.email;
var isCompleted = 'No'
var jobNumber = generator.generate(
length: 5,
numbers: true
);
// Validate
const errors = req.validationErrors();

if (errors)
res.render('index',
errors: errors
);

else
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files)
var userPath = req.user._id
var dir = './data/' + userPath + '/' + jobNumber + '/';
if (!fs.existsSync(dir))
fs.mkdirSync(dir);

else

console.log("Directory already exist");


var oldpath = files.filetoupload.path;
var newpath = dir + files.filetoupload.name;
// copy the file to a new location
fs.rename(oldpath, newpath, function (err)
if (err) throw err;
console.log('renamed complete');
const newJob = new Job(
userId: userId,
username: username,
isCompleted: isCompleted,
filepath: newpath,
jobNumber: jobNumber,
);
Job.createJob(newJob, function(err, job)
if (err) throw err;
console.log(job);
);
req.flash('success_msg', 'Job Submitted...');
res.redirect('/')
);
);

);









share|improve this question























  • stackoverflow.com/questions/39293636/…
    – Suresh Prajapati
    Nov 12 '18 at 5:54










  • @SureshPrajapati At your current reputation score you can actually "vote to close as duplicate". So if you think something is a duplicate, then please just do so. Questions can always be reopened IF there is a compelling reason that it requires a different solution from the duplicate. I will say however that this question is not about npm install, so though there's a common "underlying cause" then it's not the same thing, and does not need random links in comments either.
    – Neil Lunn
    Nov 12 '18 at 6:01











  • @SureshPrajapati whilst the error is the same the cause is different, thanks for trying though
    – Phillip Lakis
    Nov 12 '18 at 6:15










  • @PhillipLakis did u try npm cache clean --force and npm install -g npm@latest ?
    – Suresh Prajapati
    Nov 12 '18 at 6:18










  • @SureshPrajapati my error is caused by my router.POST and the rename not happening, Did you read my entire post and not just the error? And yes i tried your npm but it doesnt solve the empty field of the router.post
    – Phillip Lakis
    Nov 12 '18 at 6:20














0












0








0







Everything is working as expected in my code except if the user has not uploaded a file it crashes my node app.



The error is arising at the fs.rename part, as there is nothing uploaded the app cant rename anything and causes the following:



Error:




EPERM: operation not permitted, rename 'C:UsersxxxAppDataLocalTempupload_0a145049089fa69e9df64f8d20abb362' -> 'C:UsersxxxDropboxAutomate NodeJSLogin_Register+Submit - 0.01data5be13231807fe33f14b2834asdS9m'




Im having difficulty searching for my err and how to handle that, If anyone can point me to some resources for how to handle formidable errors and how to stop the process of the user hasn't uploaded anything it would be fantastic.



It's not a production app or anything of the like its just me learning how to deal with multiple functions and a database at once.



router.post('/submit', userisSubbed, userhasTime, (req, res, next0) => 
var userId = req.user._id;
var username = req.user.email;
var isCompleted = 'No'
var jobNumber = generator.generate(
length: 5,
numbers: true
);
// Validate
const errors = req.validationErrors();

if (errors)
res.render('index',
errors: errors
);

else
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files)
var userPath = req.user._id
var dir = './data/' + userPath + '/' + jobNumber + '/';
if (!fs.existsSync(dir))
fs.mkdirSync(dir);

else

console.log("Directory already exist");


var oldpath = files.filetoupload.path;
var newpath = dir + files.filetoupload.name;
// copy the file to a new location
fs.rename(oldpath, newpath, function (err)
if (err) throw err;
console.log('renamed complete');
const newJob = new Job(
userId: userId,
username: username,
isCompleted: isCompleted,
filepath: newpath,
jobNumber: jobNumber,
);
Job.createJob(newJob, function(err, job)
if (err) throw err;
console.log(job);
);
req.flash('success_msg', 'Job Submitted...');
res.redirect('/')
);
);

);









share|improve this question















Everything is working as expected in my code except if the user has not uploaded a file it crashes my node app.



The error is arising at the fs.rename part, as there is nothing uploaded the app cant rename anything and causes the following:



Error:




EPERM: operation not permitted, rename 'C:UsersxxxAppDataLocalTempupload_0a145049089fa69e9df64f8d20abb362' -> 'C:UsersxxxDropboxAutomate NodeJSLogin_Register+Submit - 0.01data5be13231807fe33f14b2834asdS9m'




Im having difficulty searching for my err and how to handle that, If anyone can point me to some resources for how to handle formidable errors and how to stop the process of the user hasn't uploaded anything it would be fantastic.



It's not a production app or anything of the like its just me learning how to deal with multiple functions and a database at once.



router.post('/submit', userisSubbed, userhasTime, (req, res, next0) => 
var userId = req.user._id;
var username = req.user.email;
var isCompleted = 'No'
var jobNumber = generator.generate(
length: 5,
numbers: true
);
// Validate
const errors = req.validationErrors();

if (errors)
res.render('index',
errors: errors
);

else
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files)
var userPath = req.user._id
var dir = './data/' + userPath + '/' + jobNumber + '/';
if (!fs.existsSync(dir))
fs.mkdirSync(dir);

else

console.log("Directory already exist");


var oldpath = files.filetoupload.path;
var newpath = dir + files.filetoupload.name;
// copy the file to a new location
fs.rename(oldpath, newpath, function (err)
if (err) throw err;
console.log('renamed complete');
const newJob = new Job(
userId: userId,
username: username,
isCompleted: isCompleted,
filepath: newpath,
jobNumber: jobNumber,
);
Job.createJob(newJob, function(err, job)
if (err) throw err;
console.log(job);
);
req.flash('success_msg', 'Job Submitted...');
res.redirect('/')
);
);

);






node.js express formidable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 14:53









Flimzy

37.7k96496




37.7k96496










asked Nov 12 '18 at 5:27









Phillip LakisPhillip Lakis

11




11











  • stackoverflow.com/questions/39293636/…
    – Suresh Prajapati
    Nov 12 '18 at 5:54










  • @SureshPrajapati At your current reputation score you can actually "vote to close as duplicate". So if you think something is a duplicate, then please just do so. Questions can always be reopened IF there is a compelling reason that it requires a different solution from the duplicate. I will say however that this question is not about npm install, so though there's a common "underlying cause" then it's not the same thing, and does not need random links in comments either.
    – Neil Lunn
    Nov 12 '18 at 6:01











  • @SureshPrajapati whilst the error is the same the cause is different, thanks for trying though
    – Phillip Lakis
    Nov 12 '18 at 6:15










  • @PhillipLakis did u try npm cache clean --force and npm install -g npm@latest ?
    – Suresh Prajapati
    Nov 12 '18 at 6:18










  • @SureshPrajapati my error is caused by my router.POST and the rename not happening, Did you read my entire post and not just the error? And yes i tried your npm but it doesnt solve the empty field of the router.post
    – Phillip Lakis
    Nov 12 '18 at 6:20

















  • stackoverflow.com/questions/39293636/…
    – Suresh Prajapati
    Nov 12 '18 at 5:54










  • @SureshPrajapati At your current reputation score you can actually "vote to close as duplicate". So if you think something is a duplicate, then please just do so. Questions can always be reopened IF there is a compelling reason that it requires a different solution from the duplicate. I will say however that this question is not about npm install, so though there's a common "underlying cause" then it's not the same thing, and does not need random links in comments either.
    – Neil Lunn
    Nov 12 '18 at 6:01











  • @SureshPrajapati whilst the error is the same the cause is different, thanks for trying though
    – Phillip Lakis
    Nov 12 '18 at 6:15










  • @PhillipLakis did u try npm cache clean --force and npm install -g npm@latest ?
    – Suresh Prajapati
    Nov 12 '18 at 6:18










  • @SureshPrajapati my error is caused by my router.POST and the rename not happening, Did you read my entire post and not just the error? And yes i tried your npm but it doesnt solve the empty field of the router.post
    – Phillip Lakis
    Nov 12 '18 at 6:20
















stackoverflow.com/questions/39293636/…
– Suresh Prajapati
Nov 12 '18 at 5:54




stackoverflow.com/questions/39293636/…
– Suresh Prajapati
Nov 12 '18 at 5:54












@SureshPrajapati At your current reputation score you can actually "vote to close as duplicate". So if you think something is a duplicate, then please just do so. Questions can always be reopened IF there is a compelling reason that it requires a different solution from the duplicate. I will say however that this question is not about npm install, so though there's a common "underlying cause" then it's not the same thing, and does not need random links in comments either.
– Neil Lunn
Nov 12 '18 at 6:01





@SureshPrajapati At your current reputation score you can actually "vote to close as duplicate". So if you think something is a duplicate, then please just do so. Questions can always be reopened IF there is a compelling reason that it requires a different solution from the duplicate. I will say however that this question is not about npm install, so though there's a common "underlying cause" then it's not the same thing, and does not need random links in comments either.
– Neil Lunn
Nov 12 '18 at 6:01













@SureshPrajapati whilst the error is the same the cause is different, thanks for trying though
– Phillip Lakis
Nov 12 '18 at 6:15




@SureshPrajapati whilst the error is the same the cause is different, thanks for trying though
– Phillip Lakis
Nov 12 '18 at 6:15












@PhillipLakis did u try npm cache clean --force and npm install -g npm@latest ?
– Suresh Prajapati
Nov 12 '18 at 6:18




@PhillipLakis did u try npm cache clean --force and npm install -g npm@latest ?
– Suresh Prajapati
Nov 12 '18 at 6:18












@SureshPrajapati my error is caused by my router.POST and the rename not happening, Did you read my entire post and not just the error? And yes i tried your npm but it doesnt solve the empty field of the router.post
– Phillip Lakis
Nov 12 '18 at 6:20





@SureshPrajapati my error is caused by my router.POST and the rename not happening, Did you read my entire post and not just the error? And yes i tried your npm but it doesnt solve the empty field of the router.post
– Phillip Lakis
Nov 12 '18 at 6:20













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256358%2fformidable-handle-no-uploaded-file-errors%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256358%2fformidable-handle-no-uploaded-file-errors%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus