0

I am using node in Windows environment. When I use fs.unlink(fileName), it seems to work.

After the unlink statement is executed when I go to the physical drive I could still see the file.

At this point of time if I try and delete the file manually it throws Access Denied .or if I try to create a file with the same name you get Access Denied

However, the file is automatically removed from the file system only when I stop the executing Node Script File.

Below is the code which I am using to get the image from client and uploading it to Azure Blob Storage and then removing the file.

var express = require('express');
var multer = require('multer');
var app = express();

var multerDiskConcept = multer(
{
    dest: './uploads/',
    rename: function (fieldname, filename) { return filename; }
});

app.post('/testdisk', multerDiskConcept, DiskConcept);


//http://localhost:3000/testdisk
function DiskConcept(request, response) 
{
    var azure = require('azure-storage');
    var blobService = azure.createBlobService(storageName, storageKey);
    var async = require('async');


blobService.createContainerIfNotExists('images', { publicAccessLevel: 'blob' }, function (error, result, blobresponse)
{
    if (error) 
    {
        response.status(500).send(error);
    }
    else 
    {
        var imageName = require('node-uuid').v1() + "_" + request.files.images.originalname;

        blobService.createBlockBlobFromLocalFile('images', imageName, request.files.images.path, function (error, result, blobimageresponse) 
        {
            if (error) 
            {
                response.status(500).send(error);
            }
            else 
            {                    
                var fs = require("fs");
                fs.unlink(item.imagepath, function (err) 
                {
                    if (err) 
                        response.status(500).send(err);
                    else
                        response.status(200).send("Success");
                });

            }
        });
    }
});

}

Is this the expected behavior ? or how can I handle it

Sharath
  • 2,348
  • 8
  • 45
  • 81
  • 1
    Do you still have the file open in your script somewhere? – mscdex Sep 08 '15 at 19:57
  • I have updated the entire code which I using. I am getting the image from client and uploading it to Azure Blob Storage and deleting the file. – Sharath Sep 09 '15 at 02:59

0 Answers0