Skip to content

Commit

Permalink
Merge pull request #36 from githuib/API-144_file-upload-broken
Browse files Browse the repository at this point in the history
API-144  [C# SDK] File upload broken
  • Loading branch information
Huib Piguillet authored Nov 20, 2020
2 parents 8c5d2f5 + 74217ee commit 826545a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Bynder/Sdk/Api/RequestSender/HttpRequestSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class HttpRequestSender : IHttpRequestSender
/// </summary>
public string UserAgent
{
get { return $"bynder-c-sharp-sdk/{Assembly.GetExecutingAssembly().GetName().Version.ToString()}"; }
get { return $"bynder-c-sharp-sdk/{Assembly.GetExecutingAssembly().GetName().Version}"; }
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions Bynder/Sdk/Bynder.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Product>Bynder.Sdk</Product>
<Copyright>Copyright © Bynder</Copyright>
<PackOnBuild>true</PackOnBuild>
<PackageVersion>2.2.1</PackageVersion>
<PackageVersion>2.2.2</PackageVersion>
<Authors>BynderDevops</Authors>
<Description>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.</Description>
<PackageIconUrl>https://bynder.com/static/3.0/img/favicon-black.ico</PackageIconUrl>
Expand All @@ -16,8 +16,7 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Owners>BynderDevops</Owners>
<PackageProjectUrl>https://github.com/Bynder/bynder-c-sharp-sdk</PackageProjectUrl>
<PackageReleaseNotes>- Performance and stability improvements.
- Fixed error with deserialization of ModifyMedia response</PackageReleaseNotes>
<PackageReleaseNotes>Fixes an issue that broke the file uploader</PackageReleaseNotes>
<Summary>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.</Summary>
<PackageTags>Bynder API C# SDK</PackageTags>
<Title>Bynder.Sdk</Title>
Expand Down
38 changes: 18 additions & 20 deletions Bynder/Sdk/Service/Upload/AmazonApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
36 changes: 14 additions & 22 deletions Bynder/Sdk/Service/Upload/FileUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,40 +243,32 @@ private async Task<bool> HasFinishedSuccessfullyAsync(FinalizeResponse finalizeR
}

/// <summary>
/// Registers a chunk in Bynder.
/// Registers a chunk in Bynder using <see cref="UploadRequest"/>.
/// </summary>
/// <param name="query">Query information to be able to register chunk</param>
/// <param name="uploadRequest">Upload request information</param>
/// <param name="chunkNumber">Current chunk number</param>
/// <returns>Task representing the register chunk process</returns>
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<string>
var request = new ApiRequest<object>
{
Path = $"/api/v4/upload/{query.UploadId}/",
HTTPMethod = HttpMethod.Post,
Query = query,
DeserializeResponse = false
};

return _requestSender.SendRequestAsync(request);
}

/// <summary>
/// Registers a chunk in Bynder using <see cref="UploadRequest"/>.
/// </summary>
/// <param name="uploadRequest">Upload request information</param>
/// <param name="chunkNumber">Current chunk number</param>
/// <returns>Task representing the register chunk process</returns>
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);
}

/// <summary>
Expand Down

0 comments on commit 826545a

Please sign in to comment.