Skip to content

Commit

Permalink
fix(dotnet): chunk upload
Browse files Browse the repository at this point in the history
  • Loading branch information
byawitz committed Oct 1, 2024
1 parent 4337468 commit d023f35
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions templates/dotnet/Package/Client.cs.twig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace {{ spec.title | caseUcfirst }}
{
_endpoint = endpoint;
_http = http ?? new HttpClient();

_httpForRedirect = httpForRedirect ?? new HttpClient(
new HttpClientHandler(){
AllowAutoRedirect = false
Expand Down Expand Up @@ -220,7 +220,7 @@ namespace {{ spec.title | caseUcfirst }}

public async Task<String> Redirect(
string method,
string path,
string path,
Dictionary<string, string> headers,
Dictionary<string, object?> parameters)
{
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace {{ spec.title | caseUcfirst }}
var response = await _http.SendAsync(request);
var code = (int)response.StatusCode;

if (response.Headers.TryGetValues("x-{{ spec.title | lower }}-warning", out var warnings))
if (response.Headers.TryGetValues("x-{{ spec.title | lower }}-warning", out var warnings))
{
foreach (var warning in warnings)
{
Expand Down Expand Up @@ -376,16 +376,23 @@ namespace {{ spec.title | caseUcfirst }}

if (!string.IsNullOrEmpty(idParamName) && (string)parameters[idParamName] != "unique()")
{
try
{
// Make a request to check if a file already exists
var current = await Call<Dictionary<string, object?>>(
method: "GET",
path: "$path/${params[idParamName]}",
headers,
parameters = new Dictionary<string, object?>()
path: $"{path}/{parameters[idParamName]}",
new Dictionary<string, string> { { "content-type", "application/json" } },
parameters: new Dictionary<string, object?>()
);
var chunksUploaded = (long)current["chunksUploaded"];
offset = chunksUploaded * ChunkSize;
}
catch (Exception ex)
{
// ignored as it mostly means file not found
}
}

while (offset < size)
{
Expand Down

0 comments on commit d023f35

Please sign in to comment.