使用https下载文件的Grunt任务

时间:2015-12-08 09:57:02

标签: javascript node.js https build gruntjs

我需要一个繁琐的任务来下载https上托管的文件。请求将包含一些参数,例如:

<% =Hashtable[key]%>

我尝试使用grunt-downloadfile,但我得到的只是https://server.com/services/download?what=someFile&version=1。我知道我使用的URL是正确的,因为我只需将其粘贴到浏览器中就可以了。

你会如何解决这个问题?我考虑自己编写grunt-execute节点脚本,但感觉就像重新发明轮子一样。

2 个答案:

答案 0 :(得分:2)

这是一个使用grunt-http-download库的示例工作代码,因为您可以看到有一个https并且它可以正常工作:

'use strict';

module.exports = function(grunt) {

    grunt.initConfig({
        download: {
            foo: {
                src: ['https://nodejs.org/static/images/logos/nodejs-green.png'],
                dest: '/tmp/'
            },
        }
    });

    require('load-grunt-tasks')(grunt);

    grunt.loadNpmTasks('grunt-http-download');
    grunt.registerTask('default', ['download']);
};

输出:

  

运行“download:foo”(下载)任务   将https://nodejs.org/static/images/logos/nodejs-green.png下载到/tmp/nodejs-green.png ...

     

完成下载https://nodejs.org/static/images/logos/nodejs-green.png

     

完成,没有错误。

它也适用于grunt-downloadfile库:

'use strict';

module.exports = function(grunt) {

    // Project Configuration
    grunt.initConfig({
        downloadfile: {
            files: [{
                url: 'https://nodejs.org/static/images/logos/nodejs-green.png',
                dest: '/tmp',
                name: 'test.png'
            }]
        },
    });

    require('load-grunt-tasks')(grunt);

    grunt.loadNpmTasks('grunt-downloadfile');
    grunt.registerTask('default', ['downloadfile']);
};

答案 1 :(得分:0)

我是grunt-downloadfile的创建者,对于我没有设法使库保持最新状态并解决问题感到有些ham愧。但是今天我发布了版本2。它支持HTTPS。

请在此处查看文档:{​​{3}}