我尝试从mega下载文件(图像)。我在Visual Studio 2015中从NuGet下载API MegaApiClient(github项目:https://github.com/gpailler/MegaApiClient)。 我试着这样做:
MegaApiClient mega = new MegaApiClient();
mega.Login("username", "password");
const string fileName = "fileName.jpg";
const string folderName = "FilmImage";
IEnumerable<INode> nodes = mega.GetNodes();
List<INode> folders = nodes.Where(n => n.Type == NodeType.Directory).ToList();
INode folder = folders.Where(f => f.Name == folderName).FirstOrDefault();
如何从此文件夹中获取文件?谢谢!
答案 0 :(得分:2)
您可以做的是获取所有文件的列表,并找到具有所需名称的文件:
IEnumerable<INode> nodes = mega.GetNodes();
List<INode> allFiles = nodes.Where(n => n.Type == NodeType.File).ToList();
INode myFile = allFiles.FirstOrDefault(f => f.Name == fileName);
然后你可以下载它或用它做其他事情:
DownloadFile(myFile, downloadPath)
答案 1 :(得分:0)
IEnumerable<INode> nodes = client.GetNodes();
List<INode> folders = nodes.Where(n => n.Type == NodeType.Directory).ToList();
INode myFolder = folders.FirstOrDefault(f => f.Name == "FolderName");
IEnumerable<INode> folder = client.GetNodes(myFolder);
List<INode> allFiles = folder.Where(n => n.Type == NodeType.File).ToList();
INode myFile = allFiles.FirstOrDefault(f => f.Name == "FileName");
mega.DownloadFile(myFile, "DownloadFileDirectory");