Ejemplo n.º 1
0
        /// <inheritdoc/>
        async Task <AmazonNode> IAmazonFiles.UploadNew(FileUpload fileUpload)
        {
            var url = string.Format("{0}nodes", await GetContentUrl().ConfigureAwait(false));

            if (fileUpload.AllowDuplicate)
            {
                url += "?suppress=deduplication";
            }

            var obj = new NewChild {
                name = fileUpload.FileName, parents = new string[] { fileUpload.ParentId }, kind = "FILE"
            };
            string meta = JsonConvert.SerializeObject(obj);

            var file = new SendFileInfo
            {
                StreamOpener      = fileUpload.StreamOpener,
                FileName          = fileUpload.FileName,
                FormName          = "content",
                CancellationToken = fileUpload.CancellationToken,
                BufferSize        = fileUpload.BufferSize,
                Progress          = fileUpload.Progress,
                Parameters        = new Dictionary <string, string>
                {
                    { "metadata", meta }
                }
            };

            return(await http.SendFile <AmazonNode>(HttpMethod.Post, url, file).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        async Task <AmazonNode> IAmazonFiles.Overwrite(FileUpload fileUpload)
        {
            var url  = string.Format("{0}nodes/{1}/content", await GetContentUrl().ConfigureAwait(false), fileUpload.FileName);
            var file = new SendFileInfo
            {
                StreamOpener      = fileUpload.StreamOpener,
                FileName          = fileUpload.FileName,
                FormName          = "content",
                CancellationToken = fileUpload.CancellationToken,
                Progress          = fileUpload.Progress,
            };

            return(await http.SendFile <AmazonNode>(HttpMethod.Put, url, file).ConfigureAwait(false));
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        async Task <AmazonNode> IAmazonFiles.Overwrite(string id, Func <Stream> streamCreator, CancellationToken?token, Func <long, long> progress)
        {
            var url  = string.Format("{0}nodes/{1}/content", await GetContentUrl().ConfigureAwait(false), id);
            var file = new SendFileInfo
            {
                StreamOpener      = streamCreator,
                FileName          = id,
                FormName          = "content",
                CancellationToken = token,
                Progress          = progress
            };

            return(await http.SendFile <AmazonNode>(HttpMethod.Put, url, file).ConfigureAwait(false));
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        async Task <AmazonNode> IAmazonFiles.Overwrite(string id, Func <Stream> streamCreator, CancellationToken?cancellation, Func <long, Task <long> > progress)
        {
            var content = await GetContentUrl().ConfigureAwait(false);

            var url  = $"{content}nodes/{id}/content";
            var file = new SendFileInfo
            {
                StreamOpener      = streamCreator,
                FileName          = id,
                FormName          = "content",
                Progress          = progress,
                CancellationToken = cancellation ?? CancellationToken.None
            };

            return(await http.SendFile <AmazonNode>(HttpMethod.Put, url, file).ConfigureAwait(false));
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        async Task <FileUploadResult> IAmazonFiles.UploadNew(FileUpload fileUpload)
        {
            /*
             * var url = string.Format("{0}nodes", await GetContentUrl().ConfigureAwait(false));
             * if (fileUpload.AllowDuplicate)
             * {
             *  url += "?suppress=deduplication";
             * }
             */

            var url = BuildMethodUrl("uploadfile");

            url = $"{url}&nopartial=1&folderid={fileUpload.ParentId}";

            if (fileUpload.AllowDuplicate)
            {
                url += "&renameifexists=1";
            }

            var obj = new NewChild {
                name = fileUpload.FileName, parents = new string[] { fileUpload.ParentId }, kind = "FILE"
            };
            string meta = JsonConvert.SerializeObject(obj);

            var file = new SendFileInfo
            {
                StreamOpener      = fileUpload.StreamOpener,
                FileName          = fileUpload.FileName,
                FormName          = "content",
                CancellationToken = fileUpload.CancellationToken,
                BufferSize        = fileUpload.BufferSize,
                Progress          = fileUpload.Progress,

                /* Parameters = new Dictionary<string, string>
                 *  {
                 *      { "metadata", meta }
                 *  } */
            };

            return(await http.SendFile <FileUploadResult>(HttpMethod.Post, url, file).ConfigureAwait(false));
        }