2015-02-07 196 views
1

在Windows机器上,我有一个共享文件夹=>ž映射:使用快递/上传/SENDFILE绝对路径

,我用res.senFile到一个文件返回给浏览器:

var download = config.file_dir + "/" + file; 
res.sendFile(download); 

下载值为Z:/uploads/737237213791239.pdf

我得到这个错误:

throw new TypeError('path must be absolute or specify root to res.sendFile 

我给绝对路径吗?

+1

可能它不喜欢你映射它的事实(或者Windows驱动器路径看起来不太好),因为映射的驱动器仅限于你映射它们的会话。我会尝试首先使用Windows样式反斜杠“\”或其次是UNC路径。 “\\ machinename \ share \ path \ file.ext” – user3710044 2015-02-07 15:27:32

+0

我认为你是对的。 – Alvin 2015-02-07 15:33:34

回答

0

我遇到同样的问题。我发现用正斜杠配置我的文件夹最简单,使用path.join发送。这应该工作驱动器号或UNC路径。

var path = require("path"); 
config.file_dir = "z:/folder"; 
//use forward slashes for UNC if you wish to use that instead ie //server/share 

var file = path.join(config.file_dir, urlPath); 

res.sendFile(file, (err) => { 
    if (err) { 
     res.status(err.status || 500).send(); 
    } 
});