Quantcast
Viewing all articles
Browse latest Browse all 3667

How can I upload an image to a Supabase bucket using the REST API?

I would like to use Supabase's own REST API instead of the JavaScript client library (https://supabase.com/docs/reference/javascript/storage-from-upload) provided by them.

Something like this:

const productImageFile = productData.image.split("\\")[2];        const sanitizedProductImageFile = productImageFile.replace(          /[^a-zA-Z0-9._-]/g,"_"        );        const file = new File([productData.image], sanitizedProductImageFile);        const formData = new FormData();        formData.append("file", file);        const productImageBucketApiResponse = await fetch(          `${import.meta.env.VITE_SUPABASE_URL}/storage/v1/object/${import.meta.env.VITE_SUPABASE_BUCKET_NAME}/images`,          {            method: "POST",            headers: {              apikey: import.meta.env.VITE_SUPABASE_KEY,            },            body: formData,          }        );

Viewing all articles
Browse latest Browse all 3667

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>