Giter VIP home page Giter VIP logo

Comments (6)

dougwilson avatar dougwilson commented on July 28, 2024

Can you provide fuller code and what console.dir(req.files) gives you when the error occurs?

from connect-multiparty.

khare-ashwini avatar khare-ashwini commented on July 28, 2024

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.

dougwilson avatar dougwilson commented on July 28, 2024

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.

khare-ashwini avatar khare-ashwini commented on July 28, 2024

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.

dougwilson avatar dougwilson commented on July 28, 2024

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.

dougwilson avatar dougwilson commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.