Retrieve public URL
A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset. This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.
- The bucket needs to be set to public, either via updateBucket() or by going to Storage on supabase.com/dashboard, clicking the overflow menu on a bucket and choosing "Make public"
- RLS policy permissions required:
buckets
table permissions: noneobjects
table permissions: none
- Refer to the Storage guide on how access control works
Parameters
- pathREQUIREDstring
The path and name of the file to generate the public URL for. For example `folder/image.png`.
- optionsOptionalobjectdownloadOptionalstring | boolean
Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
transformOptionalTransformOptionsTransform the asset before serving it to the client.
formatOptional"origin"Specify the format of the image requested. When using 'origin' we force the format to be the same as the original image. When this option is not passed in, images are optimized to modern image formats like Webp.
heightOptionalnumberThe height of the image in pixels.
qualityOptionalnumberSet the quality of the returned image. A number from 20 to 100, with 100 being the highest quality. Defaults to 80
resizeOptional"cover" | "contain" | "fill"The resize mode can be cover, contain or fill. Defaults to cover. Cover resizes the image to maintain it's aspect ratio while filling the entire width and height. Contain resizes the image to maintain it's aspect ratio while fitting the entire image within the width and height. Fill resizes the image to fill the entire width and height. If the object's aspect ratio does not match the width and height, the image will be stretched to fit.
widthOptionalnumberThe width of the image in pixels.
const { data } = supabase
.storage
.from('public-bucket')
.getPublicUrl('folder/avatar1.png')