0

I have combed the internet looking for a solution to this, but everything I see points back to serving static files which doesn't appear to do what I want. I'm trying to have my Express server reach out to a local file share using the following:

res.download(pathToFile, fileName, (err) => {
   if (err) throw err;
});

pathToFile is the absolute path to the file location with the file name appended at the end, but this perpetually says there is, "No such file or directory at," pathToFile location. I'm at my wits end here and could use some help.

EDIT:

To answer questions, access isn't an issue. I am using a Mac and a Windows machine to access the file share without problems. Path looks like so: //${ipAddressOfServer}/ParentFolder/ChildFolder/${fileName}

teej
  • 105
  • 3
  • 12
  • Could this simply be an access rights issue? Please add some details about your OS, the kind of file share, the path you're actually using, etc. I don't think express is important here; you could just as well try `fs.readFile()` instead. –  Aug 19 '20 at 14:41
  • How is the file share mounted? SMB? You don't need any credentials to access it? Please provide details, or this question will be closed. The fact that you as user can access a share does not necessarily mean node can do the same, too. –  Aug 19 '20 at 14:45
  • Does this answer your question? [Access file from network share path in nodejs](https://stackoverflow.com/questions/28036886/access-file-from-network-share-path-in-nodejs) –  Aug 19 '20 at 14:47
  • @ChrisG Using `fs.copyFile()` works within the Express server to go and copy it. It appears to be only when I use `res.download()` does the access issue happen. – teej Aug 19 '20 at 14:47
  • @ChrisG Using `fs.readFile()` causes a similar issue but it's appending the remaining file path to the beginning of the above path like so: `/Users/username/Documents/_DEV///${ipAddressOfServer}/ParentFolder/ChildFolder/${fileName}` – teej Aug 19 '20 at 14:58
  • I tested this and it works fine for me using forward slashes on a Windows machine. –  Aug 19 '20 at 15:01
  • @ChrisG Ok, small progress update. Running the path to the file through File Explorer and Chrome both yield the file opened and downloaded, respectively. I put that path into my `fs.readFile()` command and it errors even though the path is EXACTLY what I put into File Explorer and Chrome. – teej Aug 19 '20 at 15:10
  • That looks like node thinks it's a relative path. Did you try four backslashes instead of the two forward ones at the beginning? Again: I cannot replicate the issue, so you need to post the exact code/path, the OS your node is running on and full error messages you're getting, verbatim, in your question. –  Aug 19 '20 at 15:26

0 Answers0