public async Task <Item> CreateFolderAsync(string path, CancellationToken cancellationToken) { var @params = new ItemParams(); @params.Path = path; var content = new StringContent(@params.SerializeJson()); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var uri = BuildApiUri("files/create_folder"); var client = GetClient(); var response = await client.PostAsync(uri, content, cancellationToken); if (response.IsSuccessStatusCode) { return(await response.Content.ReadJsonAsync <Item>()); } else { throw await ProcessException(response); } }
public async Task <Stream> DownloadFileAsync(string path, CancellationToken cancellationToken) { var @params = new ItemParams(); @params.Path = path; var uri = BuildApiContentUri("files/download"); var client = GetClient(); client.DefaultRequestHeaders.Add("Dropbox-API-Arg", @params.SerializeJson(true)); var request = new HttpRequestMessage(HttpMethod.Post, uri); request.SetEmptyContent(); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); if (response.IsSuccessStatusCode) { return(new StreamWithLength(await response.Content.ReadAsStreamAsync(), response.Content.Headers.ContentLength)); } else { throw await ProcessException(response); } }