Okay guys I'm looking for a bit of help here with ...
# javascript
y
Okay guys I'm looking for a bit of help here with how to do this properly with images and "post images"
I have a website where people will be able to post content to. I'm wondering if I should use Signed URLs into a storage bucket (what I think is the proper way to do things) or just upload the image to the database and grab the URL or the blob and re work it back into an image. the database one seems to be a lot of work for what its worth. does anyone have any expertise in this?
g
If you are using hosted databases, storing images in the database is usually not a good idea based on cost. For SB it is 6x cost of storage for used space. The browser is also not going to cache images if you retrieve them from the database. What do you perceive is the advantage to putting them in the database?
y
I don't perceive that as a good idea, I was trying to use signed URLs to find an image it it was returning with resource not found. even when set to public and top level in the bucket
g
You still need policies on a public pubic, except for the public url
y
but arent signed URLs public (like it could use them in an image tag on a website)?
g
To get the signed URL you need policy access to the bucket. Once you have that I believe it goes right to storage, o would not check policy.
y
ahhh Okie dokie let me work on this real quick then
g
Bucket is actual object above for policy.
y
hey I got it to work with this!
note this is in sveltekit
Copy code
js

<script context="module">

import { supabase } from "$lib/supabase/supabaseClient";
export async function load() {    
  const {data: signedURL, error } = await supabase
  .storage
  .from('images')
  .createSignedUrl('unsplash.jpg', 60)

  // console.log(JSON.stringify(signedURL, null, 2));
  if (error) {
    console.log(error.message);
  }
  
  return {
    props: {signedURL}
  };
}
</script>

<script>
  export let signedURL
</script>
<div>
  <img src="{signedURL.signedURL}" alt="" srcset="" style="height: 500px; width:500px;">
</div>
thank you @User