Skip to content

fix: chunk upload #52

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 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Appwrite/Appwrite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<PackageId>Appwrite</PackageId>
<Version>0.10.0</Version>
<Version>0.10.1</Version>
<Authors>Appwrite Team</Authors>
<Company>Appwrite Team</Company>
<Description>
Expand Down
24 changes: 16 additions & 8 deletions Appwrite/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Client(
{
_endpoint = endpoint;
_http = http ?? new HttpClient();

_httpForRedirect = httpForRedirect ?? new HttpClient(
new HttpClientHandler(){
AllowAutoRedirect = false
Expand All @@ -69,11 +69,11 @@ public Client(
_headers = new Dictionary<string, string>()
{
{ "content-type", "application/json" },
{ "user-agent" , "AppwriteDotNetSDK/0.10.0 (${Environment.OSVersion.Platform}; ${Environment.OSVersion.VersionString})"},
{ "user-agent" , "AppwriteDotNetSDK/0.10.1 (${Environment.OSVersion.Platform}; ${Environment.OSVersion.VersionString})"},
{ "x-sdk-name", ".NET" },
{ "x-sdk-platform", "server" },
{ "x-sdk-language", "dotnet" },
{ "x-sdk-version", "0.10.0"},
{ "x-sdk-version", "0.10.1"},
{ "X-Appwrite-Response-Format", "1.6.0" }
};

Expand Down Expand Up @@ -252,7 +252,7 @@ private HttpRequestMessage PrepareRequest(

public async Task<String> Redirect(
string method,
string path,
string path,
Dictionary<string, string> headers,
Dictionary<string, object?> parameters)
{
Expand Down Expand Up @@ -301,7 +301,7 @@ public async Task<T> Call<T>(
var response = await _http.SendAsync(request);
var code = (int)response.StatusCode;

if (response.Headers.TryGetValues("x-appwrite-warning", out var warnings))
if (response.Headers.TryGetValues("x-appwrite-warning", out var warnings))
{
foreach (var warning in warnings)
{
Expand Down Expand Up @@ -408,15 +408,23 @@ public async Task<T> ChunkedUpload<T>(

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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ Appwrite is an open-source backend as a service server that abstract and simplif
Add this reference to your project's `.csproj` file:

```xml
<PackageReference Include="Appwrite" Version="0.10.0" />
<PackageReference Include="Appwrite" Version="0.10.1" />
```

You can install packages from the command line:

```powershell
# Package Manager
Install-Package Appwrite -Version 0.10.0
Install-Package Appwrite -Version 0.10.1

# or .NET CLI
dotnet add package Appwrite --version 0.10.0
dotnet add package Appwrite --version 0.10.1
```


Expand Down