gpt4 book ai didi

javascript - 使用 https 下载文件的 Grunt 任务

转载 作者:行者123 更新时间:2023-11-30 16:25:52 26 4
gpt4 key购买 nike

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

https://server.com/services/download?what=someFile&version=1

我试过使用grunt-downloadfile但我得到的只是 ECONNREFUSED。我知道我使用的 URL 是正确的,因为我只需将它粘贴到浏览器中即可使用。

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

最佳答案

这是使用 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']);
};

输出:

Running "download:foo" (download) task Downloading https://nodejs.org/static/images/logos/nodejs-green.png to /tmp/nodejs-green.png ...

Finished downloading https://nodejs.org/static/images/logos/nodejs-green.png.

Done, without errors.

它适用于 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']);
};

关于javascript - 使用 https 下载文件的 Grunt 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34152862/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com