/// <inheritdoc cref="IFileUploader"/> /// <summary> /// Uploads the file to mega.nz. /// </summary> /// <returns>The result as <see cref="string"/>.</returns> /// <seealso cref="IFileUploader"/> public async Task <string> UploadToMega() { var client = new MegaApiClient(); var possibleAccounts = this.GetPossibleAccounts("mega"); foreach (var account in possibleAccounts) { LoginMega(client, account); var info = await client.GetAccountInformationAsync(); if (info.UsedQuota + GetFileSize(this.FileName) > info.TotalQuota) { continue; } var root = GetRootFolderMega(client); var progress = this.GetProgress(); var node = await client.UploadFileAsync(this.FileName, root, progress, null); var link = await client.GetDownloadLinkAsync(node); await client.LogoutAsync(); return(link.AbsoluteUri); } return(string.Empty); }
public static async Task <SavesClass> UploadFilesAsync(string PathFileToUpload, string Username, ProgressBar PB, Label LBL) { string Filename = Path.GetFileName(PathFileToUpload); string DLink, FileSize; try { using (MALogin MAL = new MALogin()) { MegaApiClient client = MAL.Login(); INode Folder = await Task.Run(() => ChkIfFolderAndFileExist(client, Username, Filename)); if (Folder != null) { Progress <double> ze = new Progress <double>(p => PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg((int)p, PB, LBL); }))); using (FileStream stream = File.Open(@PathFileToUpload, FileMode.Open)) { INode FileUploaded = await client.UploadAsync(stream, Filename, Folder, ze); //Uploading File from PC to Mega //INode FileUploaded = await client.UploadFileAsync(PathFileToUpload, Folder, ze); //Uploading File from PC to Mega if (FileUploaded != null) { DLink = (await client.GetDownloadLinkAsync(FileUploaded)).ToString(); FileSize = (((int)(FileUploaded.Size / 1024))).ToString(); //Size in Kb client.Logout(); GC.Collect(); // TENGO QUE LLAMAR ESTO O NO DEJA BORRAR EL ARCHIVO ZIP PORQUE DICE QUE AUN ESTA EN USO. if (!DLink.Equals("")) { SavesClass SC = new SavesClass(); SC.DLink = DLink; SC.Size = FileSize; return(SC); } else { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } else { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(101, PB, LBL); })); return(null); } } } catch { PB.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { UpdateMessages.UploadMsg(102, PB, LBL); })); return(null); } }