Methods
download(resources, configuration) → {Promise.<Array.<module:Downloader~File>>}
Download the resources provided in the resources array, you can provide an object in the resources array with more specific options around downloading that particular resource. Alternatively you can set them for globally for all of the resources. Any options specified on an individual item will override any set globally.
Note: Filenames are determined based on the URL for example http://example.com/myfile.mp3
will be saved as myfile.mp3
http://example.com/somepath/somefile
will be saves as somefile
.
Parameters:
Name | Type | Description |
---|---|---|
resources |
Array.<String> |
The resources to downloading |
configuration |
downloaderConfiguration |
The options to set globally |
Example
import Agent from '@meldcx/agent';
const agent = new Agent();
const init = async() => {
await agent.onReadyAsync();
const downloaderConfig = {
checkFS: true // Check the File System for the file prior to downloading
};
const result = await agent.Downloader.download([
'https://docs.meld.cx/downloader/brooklyn-bridge.jpg',
{
toDirectory: 'drive://my-drive/my/directory/',
toFileName: 'new-york-pic.jpg',
url: 'http://docs.meld.cx/downloader/new-york.jpg'
}
], downloaderConfig);
console.log(result);
/*
Will Print
[
{
directoryPath: ["/"]
disk: "html5"
filePath: "/brooklyn-bridge.jpg"
isDirectory: false
isFile: true
name: "brooklyn-bridge.jpg"
size: 1418137
srcUrl: "https://docs.meld.cx/downloader/brooklyn-bridge.jpg"
type: "image/jpeg"
url: "http://127.0.0.1:9090/filesystem/html5/brooklyn-bridge.jpg"
},
{
directoryPath: ["/", "/virtual-drives", "/2e38eacf-97b5-42d4-99e3-79501df07961", "/my", "/directory"]
disk: "html5"
filePath: "/virtual-drives/2e38eacf-97b5-42d4-99e3-79501df07961/my/directory/new-york-pic.jpg"
isDirectory: false
isFile: true
name: "new-york-pic.jpg"
size: 1418137
srcUrl: "https://docs.meld.cx/downloader/new-york.jpg"
type: "image/jpeg"
url: "http://127.0.0.1:9090/filesystem/html5/virtual-drives/2e38eacf-97b5-42d4-99e3-79501df07961/my/directory/new-york-pic.jpg"
},
]
*\/
};
init();