0

I am trying to write a file to a network drive with nodejs.

I have a network drive mounted. I can read it and write to the network drive from shell.

I am using this to copy a file:

            fs_extra.copy('tempFileLocation', 'networkDrive' + 'uniqueName', function(err) {
                if (err) {
                    console.error(config.new_location + " -- " + err);
                } else {
                    console.log("success! ");
                }
            });

This does create the correct file name on the network drive.

The issue here is that the file is always only 0 bytes.

Update:

This writes the file to the connected network drive.

    var file5 = fs.createWriteStream('networkDrive' + 'uniqueName');
    var request5 = https.get(PICTURE_URL, function(response5) {
        response5.pipe(file5);
    });

I really did not want to write the file with https.get . I wanted to write to the /tmp folder and check for errors. Then copy to network drive from /tmp folder.

Anyone know why the fs_extra.copy is not working?

Any help is appreciated.

Thanks Phil

philipfwilson
  • 757
  • 2
  • 9
  • 21
  • Well native nodejs has two write methods one contains a length parameter... I am wondering if the fs extra module is using the write method without the length parameter.. try using native fs.write with the length param and see what happens – aguertin Jan 28 '17 at 02:06
  • https://www.npmjs.com/package/node-fs-extra This is the package I am using. I do not see a length parm there.thanks for your response. – philipfwilson Jan 28 '17 at 02:17
  • Does what I mentioned make sense? Sorry I didn't clarify but I am pretty sure the copy function uses the write function anyhow so my point is that using the native fs. write() *with the length param, will solve your issue. – aguertin Jan 28 '17 at 05:05

0 Answers0