Multer: If the file with same name and size already exists its not uploading the new file.

Created on 13 Oct 2015  路  4Comments  路  Source: expressjs/multer

Hi all,

In my case the file name should be same for every uploaded file means there will be only one image on that folder. If an image with same file name already exists then the new file is not uploaded and also i get uploadDone = true. My code is below:

var profilePicMulter = multer({
                dest: './uploads',
                rename: function (fieldname, filename) {
                        return "pic";
                },
                changeDest: function(dest, req, res) {
                        dest += req.query.picPath;
                        mkdirp(dest, function(err) {
                                if (err)        console.log('Error creating directory ',err);
                        });
                        return dest;
                },
                onFileUploadStart: function (file) {
                        console.log(file.originalname + ' is starting ...')
                },
                onFileUploadComplete: function (file) {
                        console.log(file.fieldname + ' uploaded to  ' + file.path)
                        uploadDone = true;
                },
                onError: function (error, next) {
                        console.log(error)
                        next(error)
                }
    });

Any help would be really appreciated. Thanks in advance!

Most helpful comment

@LinusU do you mean if i upload a file and the same file name already exists in the folder, it should replace it ?
in my code i dont see the file is getting replaced

but i want it to be replaced. ;(((. So how do you do that?

All 4 comments

Could you try with the latest version of multer? An 1.x release

Thanks updating to new version solved the problem :)

@LinusU do you mean if i upload a file and the same file name already exists in the folder, it should replace it ?
in my code i dont see the file is getting replaced

@LinusU do you mean if i upload a file and the same file name already exists in the folder, it should replace it ?
in my code i dont see the file is getting replaced

but i want it to be replaced. ;(((. So how do you do that?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adrienbarreau picture adrienbarreau  路  3Comments

Paul-Morris picture Paul-Morris  路  3Comments

Gabxi picture Gabxi  路  3Comments

ChristianRich picture ChristianRich  路  4Comments

trexanhvn picture trexanhvn  路  3Comments