Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
universal-file-downloader
Advanced tools
Cool repository to download file in nodejs && deno && browser
Repository to download file from everywhere !!!
It's work in the browser / nodejs / deno
If you want to use it in node js you need to specify "type" : "module" in your package.json
You can install this package via npm:
npm install universal-file-downloader
Here is a basic usage example :
import ufd from 'universal-file-downloader'
await new ufd('my_file.extension_file').downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4')
If you want to store the file in another folder
import ufd from 'universal-file-downloader'
await new ufd('my_file.extension_file').downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4')
Maybe you want the file you request need to be done via POST
import ufd from 'universal-file-downloader'
await new ufd('my_file.extension_file', { method : 'POST'}).downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4')
It's possible that you want to use a server proxy
import ufd from 'universal-file-downloader'
await new ufd('my_file.extension_file', {}, { url : 'my.server.proxy.com/', headers : {}}).downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4')
With the given configuration the url forward will become my.server.proxy.com/https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4
Be sure to configure the url as you need
Downloading from the browser is more tricky : slower than in back-end (cause browser api doesn't allow stream to blob without interruption) and require a proxy (Hello CORS) I advise you to download the video in the back-end and create a tmp link that you will return to your user then create a Blob and a download link But If you can't / don't want to use the back-end way, use the following code who is working well
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<button>Download</button>
</body>
<script type="module">
import ufd from './node_modules/universal-file-downloader/dist/index.mjs';
document.querySelector('button').addEventListener('click', async () => {
const filename = "test.mp4";
const proxyOptions = {
url : 'http://localhost:8080/',
headers : {'X-Requested-With' : 'XMLHttpRequest' }
};
await new ufd('toto.mp4', {}, proxyOptions).downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4');
});
</script>
</html>
You can also use the cdn version if you don't want to use install this package
<script type="module">
import Inspector from 'https://cdn.jsdelivr.net/npm/universal-file-downloader/dist/index.mjs';
</script>
If you are looking for a plugin to bypass cors i advise you tiny-cors-proxy
You can install this package via npm:
npm install tiny-cors-proxy
Then create a new file server.js and paste the following snipset :
import corsServer from 'tiny-cors-proxy';
corsServer.listen(8080);
Run the following command
node server.js
FAQs
Cool repository to download file in nodejs && deno && browser
We found that universal-file-downloader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.