This is a Rust client library for interacting with Supabase Storage, allowing you to perform various operations such as uploading, downloading, and managing files in your Supabase Storage bucket.
To use the Supabase Storage Rust client, you'll need to first create a Storage
instance with your Supabase configuration.
Make sure to set the required environment variables before using the client library. You can use dotenv
to load the environment variables from a .env
file.
The SupabaseConfig assumes the presence of the environment variables SUPABASEURLSTORAGE and SUPABASEAPIKEY, ensuring that both the authorization header and the base URL are appropriately configured.
```rust use supabasestorage::Storage; use supabasestorage::config::SupabaseConfig; use dotenv::dotenv;
async fn main() { dotenv().ok();
let config = SupabaseConfig::default();
let storage = Storage::new_with_config(config);
// Now you can use the `storage` instance to interact with Supabase Storage.
} ```
Utilizing the SupabaseConfig struct isn't obligatory. Alternatively, you can manually load the storage URL and API key values.
```rust use reqwest::header::HeaderValue; use supabase_storage::Storage; use serde::Deserialize;
async fn main() {
let url = "
let bucket_name = "thefux";
let response = storage
.from()
.header("Authorization", HeaderValue::from_str(&format!("Bearer {}", api_key)).unwrap())
.get_bucket_details(bucket_name)
.execute()
.await
.unwrap();
println!("{:?}", response);
// Handle the response as needed.
} ```
To get a file to a bucket from Supabase Storage, you can use the get_object
method of the Storage
instance.
```rust use supabasestorage::Storage; use supabasestorage::config::SupabaseConfig; use dotenv::dotenv;
async fn main() { dotenv().ok();
let config = SupabaseConfig::default();
let storage = Storage::new_with_config(config);
let bucket_name = "thefux";
let object = "test/bitcoin.pdf";
let response = storage
.from()
.get_object(bucket_name, object)
.execute()
.await
.unwrap();
// Handle the response as needed.
} ```
You can also update an object in the bucket using the update_object
method. This method allows you to move or copy an object from one location to another within the same bucket.
The update method is only async for now.
```rust use supabasestorage::Storage; use supabasestorage::config::SupabaseConfig; use dotenv::dotenv;
async fn main() { dotenv().ok();
let config = SupabaseConfig::default();
let storage = Storage::new_with_config(config);
let bucket_name = "thefux";
let object = "btc.pdf";
let file_path = "/user/test.pdf";
let response = storage
.from()
.update_object_async(bucket_name, object, file_path)
.await
.execute()
.await
.unwrap()
.text()
.await
.unwrap();
println!("{:?}", response);
// Handle the response as needed.
} ```
For those who prefer working with objects, rather than using the execute function, the execute_from function can be utilized, allowing for the subsequent parsing of the response.
```rust use dotenv::dotenv; use supabasestorage::Storage; use supabasestorage::config::SupabaseConfig; use serde::Deserialize;
pub struct Response { pub message: String, }
async fn main() { dotenv().ok();
let config = SupabaseConfig::default();
let storage = Storage::new_with_config(config);
let bucket_name = "thefux";
let object = "btc.pdf";
let response = storage
.from()
.delete_object(bucket_name, object)
.execute_from::<Response>()
.await
.unwrap();
println!("{:?}", response);
// Handle the response as needed.
} ```
Calling all brilliant minds and passionate developers! 🚀 Feel free to join and make a difference in the project!
This library is licensed under the MIT License. See the LICENSE file for more details.
Feel free to add more examples and documentation to this readme based on your specific use cases and requirements.