Today i checked mega.co.nz and i'm excited about some features. for example in download page it will download files on browser and after that decrypt them with javascript.
for example see this link to download a png file :
https://mega.co.nz/#!7JRgFJzJ!efpJGWuPhYczLexY19ex82nuwfs4sR_DG4JXddeClH4
in this link it will start the download inside the browser. i checked network tab in inspect element it will download parts of file with AJAX after that completed all parts of file, will save all of them in one file on computer automatically!
i want to know what they do? can you explain or link to some resource about download files inside browser like that?
also can done it only with javascript or should use some flash plugins or something like that?
For those who found this question searching for an actual recipe to download a link in text mode here is a simple python script that uses the mega.py module (install it with
sudo pip install mega.py
):The script works with python 2.7 and takes the URL of the mega.nz link.
megatools
On most Linux/posix boxes you can install megatools from standard repositories, i.e.
On ubuntu/debian:
On MacOS:
Once installed you will find a number of command line utilities, among which
megadl
which can download both shared files and your own files. Seemegadl -h
for details.A basic implementation of multipart in-browser downloader using Blob and URL APIs is brought here. It downloads a file on 4 concurrent requests and shows the progress also. Please note that it seems setting
range
header might generally not a good idea on XHR requests, have a look at this topic.While downloading:
After the download:
Another interesting topic would be implementing Pause/Resume functionality from Mega. XHR API of current browsers doesn't offer that capability so the only chance you have is to do multiple small sized chunks downloading and giving up on the downloaded part of your small chunks, the way it seems is done on Mega also. But
fetch
streaming feature can be used for that purpose, I didn't explore that yet well enough but it is documented here.Btw, have a look at these awesome projects:
Mega uses several different methods to do this: (as of 27 Nov 2013)
(source: https://eu.static.mega.co.nz/js/download_6.js)