public void CommitUploadStream(params object[] arg) { // convert the args var svc = arg[0] as DavService; var uploadRequest = arg[1] as HttpWebRequest; var fileSystemEntry = arg[2] as BaseFileEntry; var requestStream = arg[3] as WebRequestStream; // check if all data was written into stream if (requestStream.WrittenBytes != uploadRequest.ContentLength) { // nothing todo request was aborted return; } // perform the request int code; WebException e; svc.PerformWebRequest(uploadRequest, null, out code, out e); // check the ret value if (!HttpUtilityEx.IsSuccessCode(code)) { SharpBoxException.ThrowSharpBoxExceptionBasedOnHttpErrorCode(uploadRequest, (HttpStatusCode)code, e); } // adjust the lengt fileSystemEntry.Length = uploadRequest.ContentLength; }
public void CommitUploadStream(params object[] arg) { // convert the args OAuthService svc = arg[0] as OAuthService; HttpWebRequest uploadRequest = arg[1] as HttpWebRequest; long uploadSize = (long)arg[2]; BaseFileEntry fileSystemEntry = arg[3] as BaseFileEntry; #if !WINDOWS_PHONE && !MONODROID WebRequestStream requestStream = arg[4] as WebRequestStream; // check if all data was written into stream if (requestStream.WrittenBytes != uploadRequest.ContentLength) { // nothing todo request was aborted return; } #endif // perform the request int code; WebException e; svc.PerformWebRequest(uploadRequest, null, out code, out e); // check the ret value if (code != (int)HttpStatusCode.OK) { SharpBoxException.ThrowSharpBoxExceptionBasedOnHttpErrorCode(uploadRequest, (HttpStatusCode)code, e); } // set the length fileSystemEntry.Length = uploadSize; }
public void CommitUploadStream(params object[] arg) { // convert the args var svc = arg[0] as OAuthService; var uploadRequest = arg[1] as HttpWebRequest; var uploadSize = (long)arg[2]; var fileSystemEntry = arg[3] as BaseFileEntry; #if !WINDOWS_PHONE && !MONODROID var requestStream = arg[4] as WebRequestStream; // check if all data was written into stream if (requestStream.WrittenBytes != uploadRequest.ContentLength) { // nothing todo request was aborted return; } #endif // perform the request int code; WebException e; svc.PerformWebRequest(uploadRequest, null, out code, out e); // check the ret value if (code != (int)HttpStatusCode.OK) { SharpBoxException.ThrowSharpBoxExceptionBasedOnHttpErrorCode(uploadRequest, (HttpStatusCode)code, e); } if (fileSystemEntry != null) { fileSystemEntry.Length = uploadSize; fileSystemEntry.Id = fileSystemEntry.ParentID != "/" ? fileSystemEntry.ParentID + "/" + fileSystemEntry.Name : fileSystemEntry.Name; var parent = fileSystemEntry.Parent as BaseDirectoryEntry; if (parent != null) { parent.RemoveChildById(fileSystemEntry.Name); parent.AddChild(fileSystemEntry); } } }
public void CommitUploadSession(IStorageProviderSession session, IResumableUploadSession uploadSession) { if (uploadSession.Status == ResumableUploadSessionStatus.Started) { var requestService = new OAuthService(); var request = requestService.CreateWebRequest(GetCommitUploadSessionUrl(session, uploadSession), "POST", null, null, ((DropBoxStorageProviderSession)session).Context, (DropBoxToken)session.SessionToken, new Dictionary <string, string> { { "upload_id", uploadSession.GetItem <string>("UploadId") } }); int httpStatusCode; WebException httpException; requestService.PerformWebRequest(request, null, out httpStatusCode, out httpException); if (httpStatusCode != (int)HttpStatusCode.OK) { SharpBoxException.ThrowSharpBoxExceptionBasedOnHttpErrorCode((HttpWebRequest)request, (HttpStatusCode)httpStatusCode, httpException); } var rUploadSession = uploadSession as ResumableUploadSession; rUploadSession.FileId = rUploadSession.ParentId != "/" ? rUploadSession.ParentId + "/" + rUploadSession.FileName : rUploadSession.FileName; //var file = (BaseFileEntry)uploadSession.File; //file.Length = uploadSession.BytesToTransfer; //file.Id = file.ParentID != "/" ? file.ParentID + "/" + file.Name : file.Name; //var parent = file.Parent as BaseDirectoryEntry; //if (parent != null) //{ // parent.RemoveChildById(file.Name); // parent.AddChild(file); //} ((ResumableUploadSession)uploadSession).Status = ResumableUploadSessionStatus.Completed; } }