/// <summary> /// 上传文件 /// todo:修改文件 /// </summary> /// <param name="upToken">上传Token</param> /// <param name="key">key</param> /// <param name="localFile">本地文件名 todo:不使用 </param> public async Task <CallRet> PutFile(string upToken, string localFile, string key) { if (!File.Exists(localFile)) { throw new Exception(string.Format("{0} does not exist", localFile)); } PutAuthClient client = new PutAuthClient(upToken); CallRet ret; using (FileStream fs = File.OpenRead(localFile)) { int blockCnt = BlockCount(fs.Length); long fsize = fs.Length; Extra.Progresses = new BlkputRet[blockCnt]; byte[] byteBuf = new byte[BLOCKSIZE]; int readLen = BLOCKSIZE; for (int i = 0; i < blockCnt; i++) { if (i == blockCnt - 1) { readLen = (int)(fsize - (long)i * BLOCKSIZE); } fs.Seek((long)i * BLOCKSIZE, SeekOrigin.Begin); fs.Read(byteBuf, 0, readLen); BlkputRet blkRet = await ResumableBlockPut(client, byteBuf, i, readLen); if (blkRet == null) { Extra.NotifyErr(new PutNotifyErrorEvent(i, readLen, "Make Block Error")); } else { Extra.Notify(new PutNotifyEvent(i, readLen, Extra.Progresses[i])); } } ret = await Mkfile(client, key, fsize); } if (ret.OK) { OnPutFinished?.Invoke(this, ret); } else { OnPutFailure?.Invoke(this, ret); } return(ret); }
public PutNotifyEvent(int blkIdx, int blkSize, BlkputRet ret) { BlkIdx = blkIdx; BlkSize = blkSize; Ret = ret; }