Yiting Liu
Yiting Liu

Reputation: 23

How to move a local image file to another folder using Node.js?

So I uploaded an image file and store it in a local folder, the assignment requirement is to move the image file from folder A to folder B, I have no clue to do this.

app.get('/fineupload003',function(req,res){

    function moveApprovedFile(file, uuid, success, failure) {
        var sourcePath = uploadedFilesPath;
        var desPath = 'approved';
        var desDir  = desPath + "/";
        var fileDes = desDir + file.name;

        fs.access()
    };
});

Upvotes: 2

Views: 4872

Answers (1)

Sarhad Salam
Sarhad Salam

Reputation: 438

If the requirements is to just move the file and not copy it, you could rename the file which would act as moving.

fs.rename(sourcePath, desPath);

Read more on rename: https://nodejs.org/docs/latest/api/fs.html#fs_fs_rename_oldpath_newpath_callback

Upvotes: 3

Related Questions