diff --git a/Bynder/Sdk/Api/RequestSender/HttpRequestSender.cs b/Bynder/Sdk/Api/RequestSender/HttpRequestSender.cs index 7a99924..1eac981 100644 --- a/Bynder/Sdk/Api/RequestSender/HttpRequestSender.cs +++ b/Bynder/Sdk/Api/RequestSender/HttpRequestSender.cs @@ -20,7 +20,7 @@ internal class HttpRequestSender : IHttpRequestSender /// public string UserAgent { - get { return $"bynder-c-sharp-sdk/{Assembly.GetExecutingAssembly().GetName().Version.ToString()}"; } + get { return $"bynder-c-sharp-sdk/{Assembly.GetExecutingAssembly().GetName().Version}"; } } /// diff --git a/Bynder/Sdk/Bynder.Sdk.csproj b/Bynder/Sdk/Bynder.Sdk.csproj index 5f00b1b..dc8c565 100644 --- a/Bynder/Sdk/Bynder.Sdk.csproj +++ b/Bynder/Sdk/Bynder.Sdk.csproj @@ -7,7 +7,7 @@ Bynder.Sdk Copyright © Bynder true - 2.2.1 + 2.2.2 BynderDevops The main goal of this SDK is to speed up the integration of Bynder customers who use C# making it easier to connect to the Bynder API (http://docs.bynder.apiary.io/) and executing requests on it. https://bynder.com/static/3.0/img/favicon-black.ico @@ -16,8 +16,7 @@ true BynderDevops https://github.com/Bynder/bynder-c-sharp-sdk - - Performance and stability improvements. -- Fixed error with deserialization of ModifyMedia response + Fixes an issue that broke the file uploader The main goal of this SDK is to speed up the integration of Bynder customers who use C# making it easier to connect to the Bynder API (http://docs.bynder.apiary.io/) and executing requests on it. Bynder API C# SDK Bynder.Sdk diff --git a/Bynder/Sdk/Service/Upload/AmazonApi.cs b/Bynder/Sdk/Service/Upload/AmazonApi.cs index 7c44dc1..60f9821 100644 --- a/Bynder/Sdk/Service/Upload/AmazonApi.cs +++ b/Bynder/Sdk/Service/Upload/AmazonApi.cs @@ -29,28 +29,26 @@ public async Task UploadPartToAmazon(string filename, string awsBucket, UploadRe using (var client = new HttpClient()) { - using (var formData = new MultipartFormDataContent()) + var formData = new MultipartFormDataContent { - formData.Add(new StringContent(uploadRequest.MultipartParams.AWSAccessKeyid), "x-amz-credential"); - formData.Add(new StringContent(finalKey), "key"); - formData.Add(new StringContent(uploadRequest.MultipartParams.Policy), "Policy"); - formData.Add(new StringContent(uploadRequest.MultipartParams.Signature), "X-Amz-Signature"); - formData.Add(new StringContent(uploadRequest.MultipartParams.Acl), "acl"); - formData.Add(new StringContent(uploadRequest.MultipartParams.Algorithm), "x-amz-algorithm"); - formData.Add(new StringContent(uploadRequest.MultipartParams.Date), "x-amz-date"); - formData.Add(new StringContent(uploadRequest.MultipartParams.SuccessActionStatus), "success_action_status"); - formData.Add(new StringContent(uploadRequest.MultipartParams.ContentType), "Content-Type"); - formData.Add(new StringContent(filename), "name"); - formData.Add(new StringContent(chunkNumber.ToString()), "chunk"); - formData.Add(new StringContent(numberOfChunks.ToString()), "chunks"); - formData.Add(new StringContent(finalKey), "Filename"); - formData.Add(new ByteArrayContent(fileContent, 0, numberOfBytes), "file"); + { new StringContent(uploadRequest.MultipartParams.AWSAccessKeyid), "x-amz-credential" }, + { new StringContent(finalKey), "key" }, + { new StringContent(uploadRequest.MultipartParams.Policy), "Policy" }, + { new StringContent(uploadRequest.MultipartParams.Signature), "X-Amz-Signature" }, + { new StringContent(uploadRequest.MultipartParams.Acl), "acl" }, + { new StringContent(uploadRequest.MultipartParams.Algorithm), "x-amz-algorithm" }, + { new StringContent(uploadRequest.MultipartParams.Date), "x-amz-date" }, + { new StringContent(uploadRequest.MultipartParams.SuccessActionStatus), "success_action_status" }, + { new StringContent(uploadRequest.MultipartParams.ContentType), "Content-Type" }, + { new StringContent(filename), "name" }, + { new StringContent(chunkNumber.ToString()), "chunk" }, + { new StringContent(numberOfChunks.ToString()), "chunks" }, + { new StringContent(finalKey), "Filename" }, + { new ByteArrayContent(fileContent, 0, numberOfBytes), "file" } + }; - using (var response = await client.PostAsync(awsBucket, formData).ConfigureAwait(false)) - { - response.EnsureSuccessStatusCode(); - } - } + var response = await client.PostAsync(awsBucket, formData).ConfigureAwait(false); + response.EnsureSuccessStatusCode(); } } } diff --git a/Bynder/Sdk/Service/Upload/FileUploader.cs b/Bynder/Sdk/Service/Upload/FileUploader.cs index e461d14..53e81ad 100644 --- a/Bynder/Sdk/Service/Upload/FileUploader.cs +++ b/Bynder/Sdk/Service/Upload/FileUploader.cs @@ -243,15 +243,24 @@ private async Task HasFinishedSuccessfullyAsync(FinalizeResponse finalizeR } /// - /// Registers a chunk in Bynder. + /// Registers a chunk in Bynder using . /// - /// Query information to be able to register chunk + /// Upload request information + /// Current chunk number /// Task representing the register chunk process - private Task RegisterChunkAsync(RegisterChunkQuery query) + private async Task RegisterChunkAsync(UploadRequest uploadRequest, uint chunkNumber) { + var query = new RegisterChunkQuery + { + TargetId = uploadRequest.S3File.TargetId, + UploadId = uploadRequest.S3File.UploadId, + S3Filename = uploadRequest.S3Filename, + ChunkNumber = chunkNumber.ToString() + }; + query.S3Filename = $"{query.S3Filename}/p{query.ChunkNumber}"; - var request = new ApiRequest + var request = new ApiRequest { Path = $"/api/v4/upload/{query.UploadId}/", HTTPMethod = HttpMethod.Post, @@ -259,24 +268,7 @@ private Task RegisterChunkAsync(RegisterChunkQuery query) DeserializeResponse = false }; - return _requestSender.SendRequestAsync(request); - } - - /// - /// Registers a chunk in Bynder using . - /// - /// Upload request information - /// Current chunk number - /// Task representing the register chunk process - private Task RegisterChunkAsync(UploadRequest uploadRequest, uint chunkNumber) - { - return RegisterChunkAsync(new RegisterChunkQuery - { - TargetId = uploadRequest.S3File.TargetId, - UploadId = uploadRequest.S3File.UploadId, - S3Filename = uploadRequest.S3Filename, - ChunkNumber = chunkNumber.ToString() - }); + await _requestSender.SendRequestAsync(request).ConfigureAwait(false); } ///