Esempio n. 1
0
 /// <summary>
 /// 尝试秒传文件
 /// </summary>
 /// <param name="MD5">文件MD5</param>
 /// <param name="SliceMD5">文件前256K的MD5</param>
 /// <param name="CRC32">文件CRC32</param>
 /// <param name="Length">文件长度</param>
 /// <param name="UploadPath">上传路径</param>
 /// <returns>是否成功</returns>
 public static bool RapidUpload(string MD5, string SliceMD5, string CRC32, long Length, string UploadPath)
 {
     if (WebTool.GetHtml($"https://pcs.baidu.com/rest/2.0/pcs/file?method=rapidupload&access_token={Program.config.Access_Token}&content-length={Length}&content-md5={MD5}&slice-md5={SliceMD5}&path={UploadPath}").Contains("ERROR"))
     {
         return(false);
     }
     return(true);
 }
Esempio n. 2
0
        void WebClient_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
        {
            JObject jobj;

            try
            {
                jobj = JObject.Parse(Encoding.UTF8.GetString(e.Result));
            }
            catch
            {
                return;
            }
            if (TaskList.Count > 1)
            {
                ((UploadTask)TaskList[UploadingTaskID]).MD5 = (string)jobj["md5"];
                File.Delete(((UploadTask)TaskList[UploadingTaskID]).FilePath);
            }
            if (UploadingTaskID + 1 >= TaskList.Count)
            {
                if (TaskList.Count > 1)
                {
                    string[] md5List = new string[TaskList.Count];
                    for (int i = 0; i < TaskList.Count; i++)
                    {
                        md5List[i] = ((UploadTask)TaskList[i]).MD5;
                    }
                    IDictionary <string, string> parameters = new Dictionary <string, string>();
                    parameters.Add("param", JsonConvert.SerializeObject(new SuperFile {
                        block_list = md5List
                    }));
                    WebTool.CreatePostHttpResponse($"https://pcs.baidu.com/rest/2.0/file?method=createsuperfile&path={UploadPath}&access_token={Program.config.Access_Token}", parameters, null, null, Encoding.UTF8, null);
                }
                State = TaskState.完成;
                SetComplete();
            }
            else
            {
                UploadingTaskID++;
                Upload(UploadingTaskID);
            }
        }