Skip to content

Commit 803350a

Browse files
committed
Updated supabase docs
1 parent b225423 commit 803350a

File tree

2 files changed

+83
-13
lines changed

2 files changed

+83
-13
lines changed

docs/guides/examples/supabase-storage-upload.mdx

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,88 @@ import SupabaseDocsCards from "/snippets/supabase-docs-cards.mdx";
88

99
## Overview
1010

11-
This task downloads a video from a provided URL, saves it to a temporary file, and then uploads the video file to Supabase Storage using S3.
11+
This example demonstrates how to upload a video file to Supabase Storage using two different methods.
1212

13-
## Key features
13+
- [Upload to Supabase Storage using the Supabase client](/guides/examples/supabase-storage-upload#example-1-upload-to-supabase-storage-using-the-supabase-storage-client)
14+
- [Upload to Supabase Storage using the AWS S3 client](/guides/examples/supabase-storage-upload#example-2-upload-to-supabase-storage-using-the-aws-s3-client)
1415

15-
- Fetches a video from a provided URL
16-
- Uploads the video file to Supabase Storage
16+
## Upload to Supabase Storage using the Supabase client
17+
18+
This task downloads a video from a provided URL, saves it to a temporary file, and then uploads the video file to Supabase Storage using the Supabase client.
1719

18-
## Task code
20+
### Task code
1921

2022
```ts trigger/supabase-storage-upload.ts
23+
import { createClient } from "@supabase/supabase-js";
24+
import { logger, task } from "@trigger.dev/sdk/v3";
25+
import fetch from "node-fetch";
26+
27+
// Initialize Supabase client
28+
const supabase = createClient(
29+
process.env.SUPABASE_PROJECT_URL ?? "",
30+
process.env.SUPABASE_SERVICE_ROLE_KEY ?? ""
31+
);
32+
33+
export const supabaseStorageUpload = task({
34+
id: "supabase-storage-upload",
35+
run: async (payload: { videoUrl: string }) => {
36+
const { videoUrl } = payload;
37+
38+
const bucket = "my_bucket"; // Replace "my_bucket" with your bucket name
39+
const objectKey = `video_${Date.now()}.mp4`;
40+
41+
// Download video data as a buffer
42+
const response = await fetch(videoUrl);
43+
44+
if (!response.ok) {
45+
throw new Error(`HTTP error! status: ${response.status}`);
46+
}
47+
48+
const videoBuffer = await response.buffer();
49+
50+
// Upload the video directly to Supabase Storage
51+
const { error } = await supabase.storage.from(bucket).upload(objectKey, videoBuffer, {
52+
contentType: "video/mp4",
53+
upsert: true,
54+
});
55+
56+
if (error) {
57+
throw new Error(`Error uploading video: ${error.message}`);
58+
}
59+
60+
logger.log(`Video uploaded to Supabase Storage bucket`, { objectKey });
61+
62+
// Return the video object key and bucket
63+
return {
64+
objectKey,
65+
bucket: bucket,
66+
};
67+
},
68+
});
69+
```
70+
71+
### Testing your task
72+
73+
To test this task in the dashboard, you can use the following payload:
74+
75+
```json
76+
{
77+
"videoUrl": "<a-video-url>" // Replace <a-video-url> with the URL of the video you want to upload
78+
}
79+
```
80+
81+
## Upload to Supabase Storage using the AWS S3 client
82+
83+
This task downloads a video from a provided URL, saves it to a temporary file, and then uploads the video file to Supabase Storage using the AWS S3 client.
84+
85+
### Key features
86+
87+
- Fetches a video from a provided URL
88+
- Uploads the video file to Supabase Storage using S3
89+
90+
### Task code
91+
92+
```ts trigger/supabase-storage-upload-s3.ts
2193
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
2294
import { logger, task } from "@trigger.dev/sdk/v3";
2395
import fetch from "node-fetch";
@@ -33,8 +105,8 @@ const s3Client = new S3Client({
33105
},
34106
});
35107

36-
export const supabaseStorageUpload = task({
37-
id: "supabase-storage-upload",
108+
export const supabaseStorageUploadS3 = task({
109+
id: "supabase-storage-upload-s3",
38110
run: async (payload: { videoUrl: string }) => {
39111
const { videoUrl } = payload;
40112

@@ -65,7 +137,7 @@ export const supabaseStorageUpload = task({
65137
});
66138
```
67139

68-
## Testing your task
140+
### Testing your task
69141

70142
To test this task in the dashboard, you can use the following payload:
71143

docs/guides/frameworks/supabase-edge-functions-database-webhooks.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,9 @@ export const videoProcessAndUpdate = task({
163163
const tempDirectory = os.tmpdir();
164164
const outputPath = path.join(tempDirectory, `audio_${Date.now()}.wav`);
165165

166-
// Fetch the video
167166
const response = await fetch(videoUrl);
168167

169-
// Extract the audio
168+
// Extract the audio using FFmpeg
170169
await new Promise((resolve, reject) => {
171170
if (!response.body) {
172171
return reject(new Error("Failed to fetch video"));
@@ -201,7 +200,6 @@ export const videoProcessAndUpdate = task({
201200
throw error;
202201
}
203202

204-
// Convert the result object to a string
205203
const transcription = result.results.channels[0].alternatives[0].paragraphs?.transcript;
206204

207205
logger.log(`Transcription: ${transcription}`);
@@ -212,8 +210,8 @@ export const videoProcessAndUpdate = task({
212210

213211
const { error: updateError } = await supabase
214212
.from("video_transcriptions")
215-
// Set the plan to the new plan and update the timestamp
216-
.update({ transcription: transcription, video_url: videoUrl })
213+
// Update the transcription column
214+
.update({ transcription: transcription })
217215
// Find the row by its ID
218216
.eq("id", id);
219217

0 commit comments

Comments
 (0)