Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add bash snippets for storage in API side panel (#18138)

Joshen Lima8accf852561
diff --git a/studio/components/interfaces/ProjectAPIDocs/Content/Bucket.tsx b/studio/components/interfaces/ProjectAPIDocs/Content/Bucket.tsx
index 2477b2b78f9..b473075172c 100644
--- a/studio/components/interfaces/ProjectAPIDocs/Content/Bucket.tsx
+++ b/studio/components/interfaces/ProjectAPIDocs/Content/Bucket.tsx
@@ -8,7 +8,7 @@ import { DOCS_RESOURCE_CONTENT } from '../ProjectAPIDocs.constants'
import ResourceContent from '../ResourceContent'
import { ContentProps } from './Content.types'
-const Bucket = ({ language }: ContentProps) => {
+const Bucket = ({ language, apikey, endpoint }: ContentProps) => {
const { ref } = useParams()
const snap = useAppStateSnapshot()
const { data } = useBucketsQuery({ projectRef: ref })
@@ -51,6 +51,8 @@ const Bucket = ({ language }: ContentProps) => {
snippet={DOCS_RESOURCE_CONTENT.uploadFile}
codeSnippets={DOCS_RESOURCE_CONTENT.uploadFile.code({
name: resource,
+ apikey,
+ endpoint,
})}
/>
<ResourceContent
@@ -58,6 +60,8 @@ const Bucket = ({ language }: ContentProps) => {
snippet={DOCS_RESOURCE_CONTENT.deleteFiles}
codeSnippets={DOCS_RESOURCE_CONTENT.deleteFiles.code({
name: resource,
+ apikey,
+ endpoint,
})}
/>
<ResourceContent
@@ -65,6 +69,8 @@ const Bucket = ({ language }: ContentProps) => {
snippet={DOCS_RESOURCE_CONTENT.listFiles}
codeSnippets={DOCS_RESOURCE_CONTENT.listFiles.code({
name: resource,
+ apikey,
+ endpoint,
})}
/>
<ResourceContent
@@ -72,6 +78,8 @@ const Bucket = ({ language }: ContentProps) => {
snippet={DOCS_RESOURCE_CONTENT.downloadFile}
codeSnippets={DOCS_RESOURCE_CONTENT.downloadFile.code({
name: resource,
+ apikey,
+ endpoint,
})}
/>
{bucket.public ? (
@@ -80,6 +88,8 @@ const Bucket = ({ language }: ContentProps) => {
snippet={DOCS_RESOURCE_CONTENT.retrievePublicURL}
codeSnippets={DOCS_RESOURCE_CONTENT.retrievePublicURL.code({
name: resource,
+ apikey,
+ endpoint,
})}
/>
) : (
@@ -88,6 +98,8 @@ const Bucket = ({ language }: ContentProps) => {
snippet={DOCS_RESOURCE_CONTENT.createSignedURL}
codeSnippets={DOCS_RESOURCE_CONTENT.createSignedURL.code({
name: resource,
+ apikey,
+ endpoint,
})}
/>
)}
diff --git a/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.constants.ts b/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.constants.ts
index 6147433e2ae..f810bf1248a 100644
--- a/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.constants.ts
+++ b/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.constants.ts
@@ -1009,11 +1009,19 @@ Upload a file to an existing bucket. RLS policy permissions required:
- \`buckets\` table permissions: none
- \`objects\` table permissions: only \`insert\` when you are uploading new files and \`select\`, \`insert\`, and \`update\` when you are upserting files.
`,
- code: ({ name }: { name: string }) => [
+ code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
{
key: 'storage-upload-file',
title: undefined,
- bash: `# No command via bash available`,
+ bash: `
+curl -X POST '${endpoint}/storage/v1/object/${name}/folder/avatar1.png' \\
+-H 'Content-Type: image/png' \\
+-H "Authorization: Bearer ${apikey}" \\
+--data-binary @/path/to/your/file'
+-H 'Content-Type: multipart/form-data' \\
+-H "Authorization: Bearer ${apikey}" \\
+--data-raw $'your_file_data'
+ `,
js: `
const avatarFile = event.target.files[0]
const { data, error } = await supabase
@@ -1037,11 +1045,16 @@ Delete files within the bucket. RLS policy permissions required:
- \`buckets\` table permissions: none
- \`objects\` table permissions: \`delete\` and \`select\`
`,
- code: ({ name }: { name: string }) => [
+ code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
{
key: 'storage-delete-files',
title: undefined,
- bash: `# No command via bash available`,
+ bash: `
+curl -X DELETE '${endpoint}/storage/v1/object/${name}' \\
+-H "Content-Type: application/json" \\
+-H "Authorization: Bearer ${apikey}" \\
+-d '{ "prefixes": ["file_name", "another_file_name"] }'
+`,
js: `
const { data, error } = await supabase
.storage
@@ -1061,11 +1074,15 @@ List all files within the bucket. RLS policy permissions required:
- \`buckets\` table permissions: none
- \`objects\` table permissions: \`select\`
`,
- code: ({ name }: { name: string }) => [
+ code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
{
key: 'storage-list-files',
title: undefined,
- bash: `# No command via bash available`,
+ bash: `
+curl -X POST '${endpoint}/storage/v1/object/list/${name}' \\
+-H "Content-Type: application/json" \\
+-H "Authorization: Bearer ${apikey}" \\
+-d '{ "limit": 100, "offset": 0, "prefix": "", "sortBy": { "column": "name", "order": "asc" } }'`,
js: `
const { data, error } = await supabase
.storage
@@ -1089,15 +1106,20 @@ Downloads a file from a private bucket. For public buckets, make a request to th
- \`buckets\` table permissions: none
- \`objects\` table permissions: \`select\`
`,
- code: ({ name }: { name: string }) => [
+ code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
{
key: 'storage-download-file',
title: undefined,
- bash: `# No command via bash available`,
+ bash: `
+curl -X GET '${endpoint}/storage/v1/object/${name}/folder/avatar1.png' \\
+-H "Content-Type: application/json" \\
+-H "Authorization: Bearer ${apikey}" \\
+--output avatar1.png
+`,
js: `
const { data, error } = await supabase
.storage
- .from('avatars')
+ .from('${name}')
.download('folder/avatar1.png')
`,
},
@@ -1113,11 +1135,16 @@ Create a signed URL which can be used to share a file for a fixed amount of time
- \`buckets\` table permissions: none
- \`objects\` table permissions: \`select\`
`,
- code: ({ name }: { name: string }) => [
+ code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
{
key: 'storage-create-signed-url',
title: undefined,
- bash: `# No command via bash available`,
+ bash: `
+curl -X POST '${endpoint}/storage/v1/object/sign/${name}/folder/avatar1.png' \\
+-H "Content-Type: application/json" \\
+-H "Authorization: Bearer ${apikey}" \\
+-d '{ "expiresIn": 60 }'
+ `,
js: `
const { data, error } = await supabase
.storage
@@ -1137,17 +1164,20 @@ A simple convenience function to get the URL for an asset in a public bucket. If
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"
+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: none
- \`objects\` table permissions: none
`,
- code: ({ name }: { name: string }) => [
+ code: ({ name, apikey, endpoint }: { name: string; apikey: string; endpoint: string }) => [
{
key: 'storage-retrieve-public-url',
title: undefined,
- bash: `# No command via bash available`,
+ bash: `
+# No bash command available.
+# You can construct the public URL by concatenating the bucket URL with the path to the asset
+# e.g ${endpoint}/storage/v1/object/public/${name}/folder/avatar1.png`,
js: `
const { data } = supabase
.storage
diff --git a/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.tsx b/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.tsx
index 4a08358912c..366e71d8ecb 100644
--- a/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.tsx
+++ b/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.tsx
@@ -139,7 +139,7 @@ const ProjectAPIDocs = () => {
{snap.activeDocsSection[0] === 'storage' && (
<>
{snap.activeDocsSection[1] !== undefined ? (
- <Bucket language={language} />
+ <Bucket language={language} apikey={apikey} endpoint={endpoint} />
) : (
<Storage language={language} />
)}