/// <summary> /// Add data to a chunked upload given a byte array. /// </summary> /// <param name="upload">A ChunkedUpload object received from the StartChunkedUpload method</param> /// <param name="fileData">The file data</param> /// <returns>A object representing the chunked upload on success</returns> public async Task <ChunkedUpload> AppendChunkedUpload(ChunkedUpload upload, byte[] fileData) { var dataContent = new ByteArrayContent(fileData); //dataContent.Headers.ContentType = MediaTypeHeaderValue.Parse( "file" ); var queryParams = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("upload_id", upload.Upload_Id), new KeyValuePair <string, string>("offset", upload.Offset.ToString( )) }; var response = await this._client.PutAsync(string.Format("{0}/{1}/chunked_upload{2}", ApiContentBaseUrl, Version, queryParams.ToQueryString( )), dataContent ); switch (response.StatusCode) { case HttpStatusCode.OK: break; case HttpStatusCode.NotFound: throw new CloudStorageItemNotFoundException( ); default: throw new HttpException((int)response.StatusCode, response.Content.ReadAsStringAsync( ).Result); } // Read response asynchronously as JsonValue and write out objects return(await response.Content.ReadAsAsync <ChunkedUpload>(this._mediaTypeFormatters)); }
/// <summary> /// Commit a completed chunked upload /// </summary> /// <param name="upload">A ChunkedUpload object received from the StartChunkedUpload method</param> /// <param name="path">The full path of the file to upload to</param> /// <param name="overwrite">Specify wether the file upload should replace an existing file.</param> /// <returns>A object representing the chunked upload on success</returns> public async Task <MetaDataBase> CommitChunkedUpload(ChunkedUpload upload, string path, bool overwrite = true) { path = FixPath(path); var keys = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("overwrite", overwrite.ToString( )), new KeyValuePair <string, string>("upload_id", upload.Upload_Id) }; var content = new FormUrlEncodedContent(keys); var response = await this._client.PostAsync(string.Format("{0}/{1}/commit_chunked_upload/{2}{3}", ApiContentBaseUrl, Version, this.RootString, path), content ); switch (response.StatusCode) { case HttpStatusCode.OK: case HttpStatusCode.Created: break; case HttpStatusCode.NotFound: throw new CloudStorageItemNotFoundException( ); default: throw new HttpException((int)response.StatusCode, response.Content.ReadAsStringAsync( ).Result); } // Read response asynchronously as JsonValue and write out objects var i = await response.Content.ReadAsAsync <DropBoxMetaDataInternal>(this._mediaTypeFormatters); return(this.ConvertInternalToMetaData(i)); }
/// <summary> /// Commit a completed chunked upload /// </summary> /// <param name="upload">A ChunkedUpload object received from the StartChunkedUpload method</param> /// <param name="path">The full path of the file to upload to</param> /// <param name="overwrite">Specify wether the file upload should replace an existing file</param> /// <param name="parentRevision">The revision of the file you're editing</param> /// <returns>A object representing the chunked upload on success</returns> public MetaData CommitChunkedUpload(ChunkedUpload upload, string path, bool overwrite = true, string parentRevision = null) { var request = _requestHelper.CreateCommitChunkedUploadRequest(upload, path, Root, overwrite, parentRevision); var response = _restClientContent.Execute <MetaData>(request); return(response.Data); }
/// <summary> /// Add data to a chunked upload given a byte array. /// </summary> /// <param name="upload">A ChunkedUpload object received from the StartChunkedUpload method</param> /// <param name="fileData">The file data</param> /// <returns>A object representing the chunked upload on success</returns> public ChunkedUpload AppendChunkedUpload(ChunkedUpload upload, byte[] fileData) { var request = _requestHelper.CreateAppendChunkedUploadRequest(upload, fileData); var response = _restClientContent.Execute <ChunkedUpload>(request); return(response.Data); }
public RestRequest CreateCommitChunkedUploadRequest(ChunkedUpload upload, string path, string root, bool overwrite) { var request = new RestRequest(Method.POST); request.Resource = "{version}/commit_chunked_upload/{root}{path}"; request.AddParameter("version", _version, ParameterType.UrlSegment); request.AddParameter("path", path, ParameterType.UrlSegment); request.AddParameter("root", root, ParameterType.UrlSegment); request.AddParameter("overwrite", overwrite); request.AddParameter("upload_id", upload.UploadId); return(request); }
public RestRequest CreateAppendChunkedUploadRequest(ChunkedUpload upload, byte[] fileData) { var request = new RestRequest(Method.PUT); request.Resource = "{version}/chunked_upload?upload_id={upload_id}&offset={offset}&oauth_consumer_key={oauth_consumer_key}&oauth_nonce={oauth_nonce}"; request.Resource += "&oauth_token={oauth_token}&oauth_timestamp={oauth_timestamp}"; request.Resource += "&oauth_signature={oauth_signature}&oauth_signature_method={oauth_signature_method}&oauth_version={oauth_version}"; request.AddParameter("version", _version, ParameterType.UrlSegment); request.AddParameter("upload_id", upload.UploadId, ParameterType.UrlSegment); request.AddParameter("offset", upload.Offset, ParameterType.UrlSegment); request.AddParameter("file", fileData, ParameterType.RequestBody); return(request); }
private void OnChunkSuccess(ChunkedUpload chunkedUpload) { _chunksCompleted++; _lastChunkUploaded = chunkedUpload; UpdateProgress(chunkedUpload.Offset, chunkedUpload.UploadId); var offset = chunkedUpload.Offset; var nextChunk = _fileSize.GetValueOrDefault(long.MaxValue) > offset ? _chunkNeeded.Invoke(offset) : new byte[0]; var chunkLength = nextChunk.GetLength(0); if (chunkLength > 0) { _client.AppendChunkedUploadAsync(chunkedUpload, nextChunk, OnChunkSuccess, OnChunkedUploadFailure); } else { _client.CommitChunkedUploadAsync(chunkedUpload, _path, _success, _failure, _overwrite, _parentRevision); } }
public void CommitChunkedUploadAsync(ChunkedUpload upload, string path, Action <MetaData> success, Action <DropboxException> failure, bool overwrite = true, string parentRevision = null) { var request = _requestHelper.CreateCommitChunkedUploadRequest(upload, path, Root, overwrite, parentRevision); ExecuteAsync(ApiType.Content, request, success, failure); }
public void AppendChunkedUploadAsync(ChunkedUpload upload, byte[] fileData, Action <ChunkedUpload> success, Action <DropboxException> failure) { var request = _requestHelper.CreateAppendChunkedUploadRequest(upload, fileData); ExecuteAsync(ApiType.Content, request, success, failure); }