Click here to Skip to main content
15,913,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am new in C# and this is the first time to me to use this API

i am trying to upload file to me mega Account by C# App

and i succeed in upload but without any progress bar

and the API has this method "UploadFileAsync" but i cant understand every parameter in this method


this is from Object browser in VS

Quote:
IMegaApiClient.UploadFileAsync(string, CG.Web.MegaApiClient.INode, System.IProgress<double>, System.Threading.CancellationToken?)


Quote:
System.Threading.Tasks.Task<cg.web.megaapiclient.inode> UploadFileAsync(string filename, CG.Web.MegaApiClient.INode parent, System.IProgress<double> progress, [System.Threading.CancellationToken? cancellationToken = null])
Member of CG.Web.MegaApiClient.IMegaApiClient


i know filename and INode parent

but
what should i write in "System.IProgress<double> progress"
and cancellationToken

What I have tried:

public uploadFileData uploadToMega(string megaFolderName, string megaFolderID, string filePathOnComputer, string newFileNameOnMega)
        {
            //Implemnt Struct
            uploadFileData myMegaFileData = new uploadFileData();

            //Start Mega Cient
            var myMegaClient = new MegaApiClient();

            //Login To Mega
            myMegaClient.Login(Userrrr, Passss);

            //Get All (File & Folders) in Mega Account
            IEnumerable<INode> nodes = myMegaClient.GetNodes();

            //Creat List Of All Folders In Mega Account
            List<INode> megaFolders = nodes.Where(n => n.Type == NodeType.Directory).ToList();

            //Choose Exist Folder In Mega Account By Name & Id
            INode myFolderOnMega = megaFolders.Where(folder => folder.Name == megaFolderName && folder.Id == megaFolderID).FirstOrDefault();
           

            //Upload The File
            //Normal Upload
            //INode myFile = myMegaClient.UploadFile(filePathOnComputer, myFolderOnMega);

            // Upload With progress bar 
            INode myFile =  myMegaClient.UploadFileAsync(filePathOnComputer, myFolderOnMega, progressBar1, default());


            //Rename The File In Mega Server
            if (string.IsNullOrEmpty(newFileNameOnMega))
            {
                
            }
            else
            {
                myMegaClient.Rename(myFile, newFileNameOnMega);
            }
            
            //Get Download Link
            Uri downloadLink = myMegaClient.GetDownloadLink(myFile);

            myMegaFileData.megaFileId = myFile.Id;
            Clipboard.SetText(myMegaFileData.megaFileId);
            myMegaFileData.megaFileType = myFile.Type.ToString();
            myMegaFileData.megaFileName = myFile.Name;
            myMegaFileData.megaFileOwner = myFile.Owner;
            myMegaFileData.megaFileParentId = myFile.ParentId;
            myMegaFileData.megaFileCreationDate = myFile.CreationDate.ToString();
            myMegaFileData.megaFileModificationDate = myFile.ModificationDate.ToString();
            myMegaFileData.megaFileSize = myFile.Size.ToString();
            myMegaFileData.megaFileDownloadLink = downloadLink.ToString();



            myMegaClient.Logout();



            return myMegaFileData;
        } 
Posted
Updated 4-May-18 5:27am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900