将文件下载到需要权限的位置

时间:2014-11-26 12:35:03

标签: node.js download

我正在创建一个在我公司内部使用的系统。 该系统将为用户创建电子邮件签名。

创建signature.html后,我想将其下载到用户的AppData文件夹中。

var downloadPath = 'C:\\Users\\' + login + '\\AppData\\Roaming\\Microsoft\\Signatures'
download(htmlData, downloadPath, displayInstructions)

function download(url, dest, cb) {
    var file = fs.createWriteStream(url);
    var request = http.get(url, function(response) {
        response.pipe(file);
        file.on('finish', function() {
            file.close(cb);
        });
    });
}

然而,当我尝试这样做时,我得到一个"未处理的错误事件"在控制台中,Chrome调试器说net::ERR_CONNECTION_REFUSED我认为这是因为AppData文件夹受限制,有没有办法可以通过此功能传递管理权限? 我只编程了几个月,所以欢迎反馈!

所有代码:

// Various variable declaraitons...
//

app.get('/signature/createsig/result/:login/:name/:job/:DDI/:mobile', function(req, res) {
    var htmlData = fs.readFileSync('signature/Signature.htm', 'utf-8');
    var login = req.params.login
    var name = req.params.name
    var job = req.params.job
    var DDI = req.params.DDI
    var mobile = req.params.mobile
    var downloadPath = 'C:\\Users\\' + login + '\\AppData\\Roaming\\Microsoft\\Signatures';
    htmlData = htmlData.replace(/%%%name%%%/g, name)
    htmlData = htmlData.replace(/%%%job%%%/g, job)
    htmlData = htmlData.replace(/%%%DDI%%%/g, DDI)
    htmlData = htmlData.replace(/%%%mobile%%%/g, mobile)
    download(htmlData, downloadPath, displayInstructions)

    function download(url, dest, cb) {
        var file = fs.createWriteStream(url);
        var request = http.get(url, function(response) {
            response.pipe(file);
            file.on('finish', function() {
                file.close(cb);
            });
        });
    }

    function displayInstructions() {
        // Display instructions
    }
})

0 个答案:

没有答案