Exemple #1
0
        public async Task <Item> UploadSessionFinishAsync(string sessionId, string path, Stream fileStream, long offset, IProgress <StreamProgress> progress, bool autorename = false, CancellationToken cancellationToken = default(CancellationToken))
        {
            var @params = new UploadSessionParams();

            @params.Cursor = new UploadSessionCursor()
            {
                SessionId = sessionId, Offset = offset
            };
            @params.Commit = new UploadParams()
            {
                Path       = path,
                Autorename = autorename,
                Mode       = "add",
            };
            var uri     = BuildApiContentUri("files/upload_session/finish");
            var client  = GetClient();
            var request = new HttpRequestMessage(HttpMethod.Post, uri);
            var content = new StreamedContent(fileStream, progress, cancellationToken);

            client.DefaultRequestHeaders.Add("Dropbox-API-Arg", @params.SerializeJson(true));
            content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            request.Content             = content;
            var response = await client.SendAsync(request, cancellationToken);

            if (response.IsSuccessStatusCode)
            {
                return(await response.Content.ReadJsonAsync <Item>());
            }
            else
            {
                throw await ProcessException(response);
            }
        }
Exemple #2
0
        public async Task UploadSessionAppendAsync(string sessionId, Stream fileStream, long offset, IProgress <StreamProgress> progress, CancellationToken cancellationToken = default(CancellationToken))
        {
            var @params = new UploadSessionParams();

            @params.Close  = false;
            @params.Cursor = new UploadSessionCursor()
            {
                SessionId = sessionId, Offset = offset
            };
            var uri     = BuildApiContentUri("files/upload_session/append_v2");
            var client  = GetClient();
            var request = new HttpRequestMessage(HttpMethod.Post, uri);
            var content = new StreamedContent(fileStream, progress, cancellationToken);

            client.DefaultRequestHeaders.Add("Dropbox-API-Arg", @params.SerializeJson(true));
            content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            request.Content             = content;
            var response = await client.SendAsync(request, cancellationToken);

            if (!response.IsSuccessStatusCode)
            {
                throw await ProcessException(response);
            }
        }
Exemple #3
0
        public async Task <UploadSessionResult> UploadSessionStartAsync(Stream fileStream, IProgress <StreamProgress> progress, CancellationToken cancellationToken = default(CancellationToken))
        {
            var @params = new UploadSessionParams();

            @params.Close = false;
            var uri     = BuildApiContentUri("files/upload_session/start");
            var client  = GetClient();
            var request = new HttpRequestMessage(HttpMethod.Post, uri);
            var content = new StreamedContent(fileStream, progress, cancellationToken);

            client.DefaultRequestHeaders.Add("Dropbox-API-Arg", @params.SerializeJson(true));
            content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            request.Content             = content;
            var response = await client.SendAsync(request, cancellationToken);

            if (response.IsSuccessStatusCode)
            {
                return(await response.Content.ReadJsonAsync <UploadSessionResult>());
            }
            else
            {
                throw await ProcessException(response);
            }
        }