Giter Club home page Giter Club logo

storage-csharp's Introduction

Integrate your Supabase projects with C#.

NOTICE, As of v1.1.0 API Change [Breaking/Minor] Library no longer uses WebClient and instead leverages HttpClient. Progress events on Upload and Download are now handled with EventHandler<float> instead of WebClient EventHandlers.

Examples (using supabase-csharp)

public async void Main()
{
  // Make sure you set these (or similar)
  var url = Environment.GetEnvironmentVariable("SUPABASE_URL");
  var key = Environment.GetEnvironmentVariable("SUPABASE_KEY");

  await Supabase.Client.InitializeAsync(url, key);

  // The Supabase Instance can be accessed at any time using:
  //  Supabase.Client.Instance {.Realtime|.Auth|etc.}
  // For ease of readability we'll use this:
  var instance = Supabase.Client.Instance;

  // Interact with Supabase Storage
  var storage = Supabase.Client.Instance.Storage
  await storage.CreateBucket("testing")

  var bucket = storage.From("testing");

  var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file:", "");
  var imagePath = Path.Combine(basePath, "Assets", "supabase-csharp.png");

  await bucket.Upload(imagePath, "supabase-csharp.png");

  // If bucket is public, get url
  bucket.GetPublicUrl("supabase-csharp.png");

  // If bucket is private, generate url
  await bucket.CreateSignedUrl("supabase-csharp.png", 3600));

  // Download it!
  await bucket.Download("supabase-csharp.png", Path.Combine(basePath, "testing-download.png"));
}

Package made possible through the efforts of:

Join the ranks! See a problem? Help fix it!

Made with contrib.rocks.

Contributing

We are more than happy to have contributions! Please submit a PR.

storage-csharp's People

Contributors

acupofjose avatar electroknight22 avatar fantasyteddy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

storage-csharp's Issues

Anon key gives 404 result on public buckets

I'm not sure if this is the normal behaviour or not as I'm not yet familiar enough with the Storage system but I would expect to have full read access to a public bucket when using the anon key.

When trying to download a file, the client is giving me a 404 but switching it with the Admin key works fine.

{"statusCode":"404","error":"Not found","message":"The resource was not found"}

Unable to retrieve files in bucket if it contains folders

Dim files = Await client.Storage.From("BucketName")

Only seems to work if the bucket does not contain subfolders. If folders are found, an exception is thrown.

Newtonsoft.Json.JsonSerializationException: 'Error converting value {null} to type 'System.DateTime'. Path '[0].updated_at', line 1, position 43.'

InvalidCastException: Null object cannot be converted to a value type.

Add new storage features introduced in LW7 updates

Feature request

Hi there,

There has been some features added to our storage, and we made some changes to the js client library to be able to use those features. It would be great if these could be added to this client library as well!

Make HTTPClient timeout configurable

I'm uploading a 250Mb file but it fails part way with an exception:

The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.

I can see nothing in the documentation on how to configure the timeout for the upload. Ideally, I would like to just upload and it runs to completion or throws an exception. This would be preferable to guessing how long of a timeout I may possibly need.

Thank You

Return Result Object From Upload

Feature request

The Upload method on IStoreFileApi needs an IsSuccess flag and an error message.

Is your feature request related to a problem? Please describe.

I'm uploading files to a bucket, and the method is returning the path. However, the file never shows up in the bucket. Actually, I cannot upload files at all with this method. Clearly, the file is failing to upload, but I have no idea why.

Describe the solution you'd like

The Upload method should return a response model, like that in the other clients, and it should give an error to explain what went wrong. I've burned hours trying to upload a file and I still have no idea why it never shows up on the other side. It's probably just a permissions issue, but I have no feedback to tell me.

Describe alternatives you've considered

I can only think of using the JavaScript client instead.

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

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;
}

Upload progress appears to be 0 or 100 with nothing inbetween

Running the following code:

Private Async Sub test()
	Dim client = Await SupabaseManager.GetInstance.GetClient
	Dim storageBucket = client.Storage.From("testbucket")
	Dim result = Await storageBucket.Upload("c:\test.txt", "test.txt",, AddressOf ProgressStatus)
End Sub
Private Sub ProgressStatus(sender As Object, e As Single)
	Debug.WriteLine($"{Date.Now: dd MMM yyyy HH:mm:ss.fff} : Upload Status = {e}%")
End Sub

Produces the following output.

28 Feb 2023 15:33:36.186 : Upload Status = 0%
28 Feb 2023 15:33:36.186 : Upload Status = 0%
28 Feb 2023 15:33:36.214 : Upload Status = 0%
28 Feb 2023 15:33:36.215 : Upload Status = 0%
--snipped many lines --
28 Feb 2023 15:33:53.998 : Upload Status = 0%
28 Feb 2023 15:33:54.004 : Upload Status = 0%
28 Feb 2023 15:33:54.006 : Upload Status = 0%
28 Feb 2023 15:33:54.010 : Upload Status = 0%
28 Feb 2023 15:33:54.013 : Upload Status = 100%

Possibly it is being cast to an Int at some point in the process?

Error when uploading file bigger than 5GB

Bug report

Describe the bug

When uploading a file which is bigger than 5GB, on the Pro Plan with a global limit of 20GB the following error is returned:

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
 at Newtonsoft.Json.JsonTextReader.ParseValue()
 at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
 at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
 at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
 at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
 at Supabase.Storage.Extensions.HttpClientProgress.UploadAsync(HttpClient client, Uri uri, Stream stream, Dictionary`2 headers, Progress`1 progress)
 at Supabase.Storage.StorageFileApi.UploadOrUpdate(String localPath, String supabasePath, FileOptions options, EventHandler`1 onProgress)
 at Supabase.Storage.StorageFileApi.Upload(String localFilePath, String supabasePath, FileOptions options, EventHandler`1 onProgress, Boolean inferContentType) 

This is triggered because the response is not a json but a 413 error from Cloudflare:

<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>cloudflare</center>
</body>
</html> 

System information

  • Version of supabase-csharp: 0.16.1
  • Version of supabase-storage-csharp: 1.4.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.