Skip to main content

wowlab_supabase/
storage.rs

1use reqwest::Method;
2
3use crate::{Result, SupabaseClient, client::check_response};
4
5impl SupabaseClient {
6    /// Upload an object to Supabase Storage, overwriting any existing object at `path`.
7    ///
8    /// # Errors
9    ///
10    /// Returns an error when the upload request fails or Storage rejects it.
11    pub async fn upload_object(
12        &self,
13        bucket: &str,
14        path: &str,
15        bytes: Vec<u8>,
16        content_type: &str,
17        cache_control: &str,
18    ) -> Result<()> {
19        let url = format!("{}/storage/v1/object/{bucket}/{path}", self.project_url);
20
21        tracing::debug!(%url, "Uploading Supabase object");
22
23        let response = self
24            .request(Method::POST, &url)
25            .header("Content-Type", content_type)
26            .header("Cache-Control", cache_control)
27            .header("x-upsert", "true")
28            .body(bytes)
29            .send()
30            .await?;
31
32        check_response(response).await?;
33
34        Ok(())
35    }
36}