Comments (6)
Can you provide fuller code and what console.dir(req.files)
gives you when the error occurs?
from connect-multiparty.
Here's the output of console.dir(req.files)
and console.log(err)
: Paste
The rest of the code involves making a database entry and rendering a response, but i don't think it matters much as the scripts halt at the error handler.
from connect-multiparty.
Thanks. I still at least need some kind of code. Like when are you doing the fs.rename
, for example. Is it is the part
event directly? Somewhere else? Are you even using events your callbacks? etc.
from connect-multiparty.
Ok, let's try try giving some more detail -
var temp_path = req.files.doc.path,
target_path = './uploads/' + req.files.doc.name
//Some entries added to the database
var a = new Model({
key : value,
})
fs.rename(temp_path, target_path, function(err){
if(err){
console.log(err);
req.flash('error', { msg : 'An error occurred in renaming the file' });
return res.redirect('back');
}
fs.unlink(temp_path, function(){
if(err){
console.log(err)
req.flash('error', { msg : 'An error occurred in unlinking the file' });
return res.redirect('back');
}
a.save(function(err, up){
if(err)
console.log(err);
});
req.flash('success', { msg : req.files.doc.originalFilename + ' upload successfully '});
})
I'm not sure whether this would help much, but this is all there is
from connect-multiparty.
So, node.js will give the error rename ENOENT
if either side is not found. It's possible the path to your uploads folder is incorrect or the uploads folder does not exist (from your target_path
variable). You are also not even using an absolute path there, so you may have a bad assumption as to where that path is relative from (hint: relative paths for fs
are not the same as for require
).
Please add the following right before your fs.rename
call:
var path = require('path');
var dir = path.dirname(path.resolve(target_path));
if (!fs.existsSync(dir)) throw new Error(dir + " does not exist; you need to make it");
and see if it throws
from connect-multiparty.
I'm going to close this since I haven't heard back from you. Feel free to post a comment, though.
from connect-multiparty.
Related Issues (20)
- Input namespace parsing HOT 2
- Stack overflow on multipart upload with domains HOT 24
- Error: ENOENT, open '......' when using uploadDir HOT 2
- can you support koa? HOT 1
- AWS upload. HOT 1
- Question - How do I delete the (temp) files on the server? HOT 2
- update multiparty to 4.1.3 HOT 3
- "High severity" security vulnerability affecting latest release (v2.0.0) HOT 1
- stream ended unexpectedly HOT 2
- Error: stream ended unexpectedly HOT 13
- About article last word HOT 1
- upload file save local HOT 3
- File upload from android device to node server HOT 4
- Uploading a file from Postman/Futter HOT 2
- Unlink file when request timed out HOT 2
- I have the same issue if I don't send any body from post man to any service. What is the wrong ?? and how to fix it ?? HOT 2
- req.files empty on nodejs 14 HOT 38
- TypeError: os.tmpDir is not a function HOT 2
- req.files is an empty object HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connect-multiparty.