Download remote file over HTTP
September 24, 2025 ยท View on GitHub
Download remote file over HTTP to the file system of a Server. Download is efficient, runs in chunks writing data as available directly to FS via stream without holding it in RAM. If error or timeout occurred โ unfinished file will get removed from file system.
/*
* @locus Server
*/
await FilesCollection#loadAsync(url [, opts: LoadOpts, proceedAfterUpload: boolean]): Promise<FileObj>;
Write file to file system from remote URL (external resource) and add record to FilesCollection
url{string} - Full address to file, likehttps://example.com/sample.pngopts?{LoadOpts} - Optional Recommended properties:opts.fileName{string} - File name with extension, likename.extopts.headers{object} - Request HTTP headers, to use when requesting the fileopts.meta{object} - Object with custom meta-dataopts.type{string} - Mime-type, likeimage/png, if not set - mime-type will be taken from response headersopts.size{number} - File size in bytes, if not set - file size will be taken from response headersopts.userId{string} - UserId, default:nullopts.fileId{string} - id, optional - if not set - Random.id() will be usedopts.timeout{number} - timeout in milliseconds, default:360000(6 mins); Set to0to disable timeout; Disabling timeout not recommended, sockets won't get closed until server rebooted
proceedAfterUpload?{boolean} - Optional ProceedonAfterUploadhook (if defined) after external source is loaded to FS- Returns {Promise
} - File Object from DB
/*
* @locus Server
*/
import { FilesCollection } from 'meteor/ostrio:files';
const imagesCollection = new FilesCollection({ collectionName: 'images' });
const fileObj = await imagesCollection.loadAsync('https://raw.githubusercontent.com/veliovgroup/Meteor-Files/master/logo.png', {
fileName: 'logo.png',
fileId: 'abc123myId', //optional
timeout: 60000, // optional timeout
meta: {}
});