Download a file
Downloads a file from a private bucket. For public buckets, make a request to the URL returned from getPublicUrl
instead.
- RLS policy permissions required:
buckets
table permissions: noneobjects
table permissions:select
- Refer to the Storage guide on how access control works
Parameters
- pathREQUIREDstring
The full path and file name of the file to be downloaded. For example `folder/image.png`.
- optionsOptionalobjecttransformOptionalTransformOptions
Transform 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, error } = await supabase
.storage
.from('avatars')
.download('folder/avatar1.png')