Skip to content

fix(dotnet): chunk upload #991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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