本文介绍了如何在mega API中进行uploadfileasync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我是C#的新手,这是我第一次使用这个API i我试图上传文件给我C#App的大型账户 我成功上传但没有任何进度条 和API有这个方法UploadFileAsync但我无法理解这个方法中的每个参数 这是来自VS中的对象浏览器 i know filename和INode parent 但是 我应该在System.IProgress< double> progress中写什么 和cancellationToken 我尝试过: public uploadFileData uploadToMega(string megaFolderName,string megaFolderID,string filePathOnComputer,string newFileNameOnMega) { // Implemnt Struct uploadFileData myMegaFileData = new uploadFileData(); //启动Mega Cient var myMegaClient = new MegaApiClient(); //登录Mega myMegaClient.Login(Userrrr,Passss); //在Mega账户中获取全部(文件和文件夹) IEnumerable< INode> nodes = myMegaClient.GetNodes(); //创建超级账户中所有文件夹的列表列表< INode> megaFolders = nodes.Where(n => n.Type == NodeType.Directory).ToList(); //按名称选择Mega账户中的存在文件夹& Id INode myFolderOnMega = megaFolders.Where(folder => folder.Name == megaFolderName&& folder.Id == megaFolderID).FirstOrDefault(); //上传文件 //正常上传 // INode myFile = myMegaClient.UploadFile(filePathOnComputer,myFolderOnMega); //使用进度条上传 INode myFile = myMegaClient.UploadFileAsync(filePathOnComputer,myFolderOnMega,progressBar1,default()); //重命名Mega Server中的文件 if(string.IsNullOrEmpty(newFileNameOnMega)) { } else { myMegaClient.Rename(myFile,newFileNameOnMega); } //获取下载链接 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(); 返回myMegaFileData; } 解决方案 i am new in C# and this is the first time to me to use this APIi 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 VSi know filename and INode parentbut what should i write in "System.IProgress<double> progress"and cancellationTokenWhat 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; } 解决方案 这篇关于如何在mega API中进行uploadfileasync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 06:09