我在Ubuntu上使用了Mega Api的python 2.7 Wrapper。使用以下代码,我可以将一组文件上传到我的Mega帐户,但是我想知道如何将文件上传到我帐户上的特定文件夹。
from mega import Mega
import os
from os import listdir
from os.path import isfile, join
mega = Mega()
mega._login_user('email','password')
def absoluteFilePaths(directory):
for dirpath,_,filenames in os.walk(directory):
for f in filenames:
yield os.path.abspath(os.path.join(dirpath, f))
directory = '/home/caioignm/test_folder'
file_path_generator = absoluteFilePaths(directory)
for file_path in file_path_generator:
mega.upload(file_path)
在我的Mega帐户上,我有一个文件夹'Personal',里面有其他文件夹,'Vacations',我的所有文件都存储在那里。当我上传而不引用目标路径时,文件存储在根目录中。
我尝试按照mega包的帮助说明进行操作,但是我没有找到如何设置文件的目标文件夹。
Help on method upload in module mega.mega:
upload(self, filename, dest=None, dest_filename=None) method of mega.mega.Mega instance
##########################################################################
# UPLOAD
执行mega.upload('filename', 'Personal/Vacations')
我没有收到任何错误消息,但我的文件也没有上传
答案 0 :(得分:1)
就这么简单,就像这样:
Folder = mega.find('my_mega_folder')
mega.upload('yourfile.txt', Folder[0])
我已将其添加到您的代码中:
from mega import Mega
import os
from os import listdir
from os.path import isfile, join
mega = Mega()
mega._login_user('email','password')
def absoluteFilePaths(directory):
for dirpath,_,filenames in os.walk(directory):
for f in filenames:
yield os.path.abspath(os.path.join(dirpath, f))
directory = '/home/caioignm/test_folder'
file_path_generator = absoluteFilePaths(directory)
Folder = mega.find('your_folder') #change it with the folder in your mega
for file_path in file_path_generator:
mega.upload(file_path, Folder[0])
答案 1 :(得分:0)
将文件上传到目标文件夹:
folder = m.find('my_mega_folder') m.upload('myfile.doc', folder[0])