Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
Expand All @@ -9,6 +10,7 @@
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using FileOptions = Supabase.Storage.FileOptions;

namespace Storage.Tests.Files
{
Expand Down Expand Up @@ -77,6 +79,17 @@ public async Task UploadOrResume_ShouldResumeCachedSessionWithoutCreating()
}
}

[TestMethod]
public async Task UploadOrResume_ShouldCloseTheLocalFile()
{
var path = Path.GetTempFileName();
await File.WriteAllBytesAsync(path, Payload);
await this.client.From(Bucket).UploadOrResume(path, FileName, new FileOptions());
FluentActions.Invoking(() => File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None).Dispose())
.Should().NotThrow("the caller must be able to move or delete the file after the upload");
File.Delete(path);
}

private void StubTusEndpoints()
{
var length = Payload.Length.ToString(CultureInfo.InvariantCulture);
Expand Down
8 changes: 4 additions & 4 deletions packages/Storage/Storage/Extensions/HttpClientProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public static async Task<HttpResponseMessage> UploadAsync(
}
}

public static Task<HttpResponseMessage> UploadOrContinueFileAsync(
public static async Task<HttpResponseMessage> UploadOrContinueFileAsync(
this HttpClient client,
Uri uri,
string filePath,
Expand All @@ -263,16 +263,16 @@ public static Task<HttpResponseMessage> UploadOrContinueFileAsync(
CancellationToken cancellationToken = default
)
{
var fileStream = new FileStream(filePath, mode: FileMode.Open, FileAccess.Read);
return ResumableUploadAsync(
using var fileStream = new FileStream(filePath, mode: FileMode.Open, FileAccess.Read);
return await ResumableUploadAsync(
client,
uri,
fileStream,
metadata,
headers,
progress,
cancellationToken
);
).ConfigureAwait(false);
}

public static Task<HttpResponseMessage> UploadOrContinueByteAsync(
Expand Down
Loading