Michele Boscagin Michele Boscagin - 9 days ago 8
C# Question

MEGA Api: Dowload a file

I try to download a file (an image) from mega. I download the API MegaApiClient from NuGet in Visual Studio 2015 (github project: https://github.com/gpailler/MegaApiClient).
I try to do this:

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();


How to get the file from this folder? Thanks!

Answer

What you could do is get a list of all the files and find the one with the required name:

IEnumerable<INode> nodes = mega.GetNodes();
List<INode> allFiles = nodes.Where(n => n.Type == NodeType.File).ToList();
INode myFile = allFiles.FirstOrDefault(f => f.Name == fileName);

You could then download it or do something else with it:

DownloadFile(myFile, downloadPath)