Download Files From Mega
Here we are going to download files from mega using download_url() methods.
Python3
from mega import Mega mega = Mega() m = mega.login(email, password) # FIND FILE file = m.find( 'myfile.doc' ) # THEN DOWNLOAD USING THE FILE OBJECT m.download( file ) # DOWNLOAD FILE USING MEGA FILE URL m.download_url( 'https: / / mega.co.nz / #!3tUF2KQD!Rg-zOOUIs9L\ ipsqwH9c_9ZOfRjZ48Xb5k2I1M6QTMa4') # SPECIFY DOWNLOAD LOCATION m.download( file , '/home/john-smith/Desktop' ) |
Output:
Searching File
Searching file requires the use of the find() function, Here if the file is found it will be a dictionary containing various info about the file, else the file will just be a none type
Python3
from mega import Mega mega = Mega() m = mega.login(email, password) filename = "" file = m.find(filename) print ( file ) |
Output:
Rename a file or a folder
Here we will rename a file using rename() methods.
Python3
from mega import Mega mega = Mega() m = mega.login(email, password) oldFilename = "data.csv" newFilename = "renamed_data.csv" file = m.find(oldFilename) m.rename( file , newFilename) |
Output:
How to share a public link of the file so that anyone can download?
get_link() method to return the link of the specific file.
Python3
# Get the File from mega import Mega mega = Mega() m = mega.login(email, password) file = m.find( "data.csv" ) # Use it in get_link function link = m.get_link( file ) # It will print the link print (link) |
Output:
How to Use Mega.nz API With Python?
In this article, we are going to see how to use mega.nz API with Python. MEGA.NZ is End-to-end encrypted and the encryption keys are owned by us. It means that mega.NZ employees won’t be able to read personal data. Mega.py is a great Python module for interacting with mega.nz API. It provides easy to use functions that can be used for functions like –
- login
- uploading
- downloading
- deleting
- searching
- sharing
- renaming