Renaming file and folders support
This commit is contained in:
parent
15cb6e06f0
commit
40f9fb95c2
2 changed files with 25 additions and 0 deletions
|
@ -7,6 +7,7 @@ Python library for the Mega.co.nz API, currently supporting:
|
|||
- deleting
|
||||
- searching
|
||||
- sharing
|
||||
- renaming
|
||||
|
||||
This is a work in progress, further functionality coming shortly.
|
||||
|
||||
|
@ -68,6 +69,11 @@ m.download(file, '/home/john-smith/Desktop')
|
|||
```python
|
||||
m.create_folder('new_folder')
|
||||
```
|
||||
### Rename a file or a folder
|
||||
```python
|
||||
file = m.find('myfile.doc')
|
||||
m.rename(file, 'my_file.doc')
|
||||
```
|
||||
### Search account for a file, and get its public link
|
||||
```python
|
||||
file = m.find('myfile.doc')
|
||||
|
|
19
mega/mega.py
19
mega/mega.py
|
@ -584,3 +584,22 @@ class Mega(object):
|
|||
'i': self.request_id})
|
||||
#return API msg
|
||||
return data
|
||||
|
||||
def rename(self, file, new_name):
|
||||
file = file[1]
|
||||
#create new attribs
|
||||
attribs = {'n': new_name}
|
||||
#encrypt attribs
|
||||
encrypt_attribs = base64_url_encode(encrypt_attr(attribs, file['k']))
|
||||
encrypted_key = a32_to_base64(encrypt_key(file['key'], self.master_key))
|
||||
|
||||
#update attributes
|
||||
data = self.api_request([{
|
||||
'a': 'a',
|
||||
'attr': encrypt_attribs,
|
||||
'key': encrypted_key,
|
||||
'n': file['h'],
|
||||
'i': self.request_id}])
|
||||
|
||||
#return API msg
|
||||
return data
|
||||
|
|
Loading…
Reference in a new issue