supabase-community/storage-csharp

WebClient not supported in Blazor Wasm, need to switch to HttpClient

rr-code-base opened this issue · 3 comments

Am using supabase-csharp 0.4.4 and am getting errors trying to load a file in a blazor wasm project but blazor wasm doesn't support WebClient so this needs to use HttpClient instead:

private Task<string> UploadOrUpdate (byte[] data, string supabasePath, FileOptions options, UploadProgressChangedEventHandler onProgress = null)
{
	TaskCompletionSource<string> tsc = new TaskCompletionSource<string> ();
	WebClient webClient = new WebClient ();
	Uri address = new Uri (Url + "/object/" + GetFinalPath (supabasePath));
	foreach (KeyValuePair<string, string> header in Headers) {
		webClient.Headers.Add (header.Key, header.Value);
	}
	webClient.Headers.Add ("cache-control", "max-age=" + options.CacheControl);
	webClient.Headers.Add ("content-type", options.ContentType);
	if (options.Upsert) {
		webClient.Headers.Add ("x-upsert", options.Upsert.ToString ());
	}
	if (onProgress != null) {
		webClient.UploadProgressChanged += onProgress;
	}
	webClient.UploadDataCompleted += delegate(object sender, UploadDataCompletedEventArgs args) {
		if (args.Error != null) {
			tsc.SetException (args.Error);
		} else {
			tsc.SetResult (GetFinalPath (supabasePath));
		}
	};
	webClient.UploadDataAsync (address, data);
	return tsc.Task;
}

Hm. Thanks for the issue! The use of WebClient was for the sake of download progress events. I’m not sure we can do that with HttpClient. If you’re willing to do a PR very open to it! Otherwise I’ll get to this probably by the end of the week

@rr-code-base available in release v1.1.0 with some API changes. To be pushed to the main supabase package shortly

Awesome! Will check it out!