private async Task <long> UpLoadFile(AllFolder folder, string fileid, long startsize, string filename, long filemaxsize) { string uploadurl = null; string method = "PUT"; string naem = System.IO.Path.GetFileName(filename); UpLoadUrl Url = new UpLoadUrl(naem, fileid, maxsize, accesstoken); if (driveinfo.token.Drive == "Google") { uploadurl = await Url.GetGoogleUploadUrl(); } else if (driveinfo.token.Drive == "OneDrive") { uploadurl = await Url.GetOneDriveUrl(); } else if (driveinfo.token.Drive == "DropBox") { uploadurl = string.Format("https://api-content.dropbox.com/1/chunked_upload?overwrite=true&autorename=true"); } try { System.IO.Stream filestream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite); HttpWebResponse respone = null; respone = await RequstHttp(method, uploadurl, null, accesstoken, filestream, filemaxsize, StreamBlockSize, startsize); if (driveinfo.token.Drive == "DropBox") { Dictionary <string, object> text = HttpHelper.DerealizeJson(respone.GetResponseStream()); string uploadid = text["upload_id"].ToString(); Dictionary <string, string> parameter = new Dictionary <string, string>(); parameter.Add("upload_id", uploadid); respone = await HttpHelper.RequstHttp("POST", string.Format("https://api-content.dropbox.com/1/commit_chunked_upload/auto/{0}", System.IO.Path.Combine(fileid, filename).Replace("\\", "/")), parameter, accesstoken); } Dictionary <string, object> file = HttpHelper.DerealizeJson(respone.GetResponseStream()); filestream.Close(); return(startsize); //mstream.Close(); } catch (WebException e) { throw e; } catch (Exception e) { throw e; } }
public async override void StreamThread() { int ReadSize = 0; label.Text = "0%"; label.Name = "label"; label.AutoSize = true; progress.Value = 0; progress.Maximum = 100; progress.Controls.Add(label); progress.Size = new System.Drawing.Size(181, 23); this.OnControl(this, progress); byteArray = new byte[FileTransfer.StreamBlockSize]; ReadSize = 0; System.IO.MemoryStream mstream = new System.IO.MemoryStream(); string uploadurl = null; string method = "PUT"; presize = 0; endsize = 0; UpLoadUrl Url = new UpLoadUrl(path, fildid, maxsize, accesstoken); if (driveinfo.token.Drive == "Google") { uploadurl = await Url.GetGoogleUploadUrl(); } else if (driveinfo.token.Drive == "OneDrive") { uploadurl = await Url.GetOneDriveUrl(); } else if (driveinfo.token.Drive == "DropBox") { uploadurl = string.Format("https://api-content.dropbox.com/1/chunked_upload?overwrite=true&autorename=true"); } try { HttpWebResponse respone = null; respone = await RequstHttp(method, uploadurl, null, accesstoken, filestream, maxsize, StreamBlockSize); if (driveinfo.token.Drive == "DropBox") { Dictionary <string, object> text = HttpHelper.DerealizeJson(respone.GetResponseStream()); string uploadid = text["upload_id"].ToString(); Dictionary <string, string> parameter = new Dictionary <string, string>(); parameter.Add("upload_id", uploadid); respone = await HttpHelper.RequstHttp("POST", string.Format("https://api-content.dropbox.com/1/commit_chunked_upload/auto/{0}", System.IO.Path.Combine(fildid, path).Replace("\\", "/")), parameter, accesstoken); } Dictionary <string, object> file = HttpHelper.DerealizeJson(respone.GetResponseStream()); CloudFiles item = CreateFile(file); this.OnComplete(this, progress, item, fildid, group); filestream.Close(); mstream.Close(); } catch (WebException e) { MessageBox.Show("전송오류: " + e.Message); return; } catch (Exception e) { MessageBox.Show("전송오류: " + e.Message); return; } }