Files
supabase/apps/temp-docs/docs/reference/javascript/storage-from-getpublicurl.mdx
2022-05-30 14:52:54 +08:00

83 lines
1.8 KiB
Plaintext

---
id: storage-from-getpublicurl
title: 'from.getPublicUrl()'
slug: storage-from-getpublicurl
custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supabase.yml
---
import Tabs from '@theme/Tabs'
import TabsPanel from '@theme/TabsPanel'
Retrieve URLs for assets in public buckets
<Tabs
defaultActiveId="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabsPanel id="js" label="js">
```js
const { publicURL, error } = supabase.storage
.from('public-bucket')
.getPublicUrl('folder/avatar1.png')
```
</TabsPanel>
</Tabs>
## Parameters
<ul className="method-list-group">
<li className="method-list-item">
<h4 className="method-list-item-label">
<span className="method-list-item-label-name">
path
</span>
<span className="method-list-item-label-badge required">
required
</span>
<span className="method-list-item-validation">
<code>string</code>
</span>
</h4>
<div class="method-list-item-description">
The file path to be downloaded, including the path and file name. For example `folder/image.png`.
</div>
</li>
</ul>
## Notes
- The bucket needs to be set to public, either via [updateBucket()](/docs/reference/javascript/storage-updatebucket) or by going to Storage on [app.supabase.com](https://app.supabase.com), clicking the overflow menu on a bucket and choosing "Make public"
- Policy permissions required:
- `buckets` permissions: none
- `objects` permissions: none
## Examples
### Returns the URL for an asset in a public bucket
<Tabs
defaultActiveId="js"
groupId="reference/supabase-js"
values={[{ label: 'JavaScript', value: 'js' }]}>
<TabsPanel id="js" label="js">
```js
const { publicURL, error } = supabase.storage
.from('public-bucket')
.getPublicUrl('folder/avatar1.png')
```
</TabsPanel>
</Tabs>