Overview
This example shows how to upload a video file to Supabase Storage using two different methods.
Upload to Supabase Storage using the Supabase client
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.
Task code
trigger/supabase-storage-upload.ts
import { createClient } from "@supabase/supabase-js";
import { logger, task } from "@trigger.dev/sdk/v3";
import fetch from "node-fetch";
const supabase = createClient(
process.env.SUPABASE_PROJECT_URL ?? "",
process.env.SUPABASE_SERVICE_ROLE_KEY ?? ""
);
export const supabaseStorageUpload = task({
id: "supabase-storage-upload",
run: async (payload: { videoUrl: string }) => {
const { videoUrl } = payload;
const bucket = "my_bucket";
const objectKey = `video_${Date.now()}.mp4`;
const response = await fetch(videoUrl);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const videoBuffer = await response.buffer();
const { error } = await supabase.storage.from(bucket).upload(objectKey, videoBuffer, {
contentType: "video/mp4",
upsert: true,
});
if (error) {
throw new Error(`Error uploading video: ${error.message}`);
}
logger.log(`Video uploaded to Supabase Storage bucket`, { objectKey });
return {
objectKey,
bucket: bucket,
};
},
});
Testing your task
To test this task in the dashboard, you can use the following payload:
{
"videoUrl": "<a-video-url>"
}
Upload to Supabase Storage using the AWS S3 client
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.
Key features
- Fetches a video from a provided URL
- Uploads the video file to Supabase Storage using S3
Task code
trigger/supabase-storage-upload-s3.ts
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { logger, task } from "@trigger.dev/sdk/v3";
import fetch from "node-fetch";
const s3Client = new S3Client({
region: process.env.SUPABASE_REGION,
endpoint: `https://${process.env.SUPABASE_PROJECT_ID}.supabase.co/storage/v1/s3`,
credentials: {
accessKeyId: process.env.SUPABASE_ACCESS_KEY_ID ?? "",
secretAccessKey: process.env.SUPABASE_SECRET_ACCESS_KEY ?? "",
},
});
export const supabaseStorageUploadS3 = task({
id: "supabase-storage-upload-s3",
run: async (payload: { videoUrl: string }) => {
const { videoUrl } = payload;
const response = await fetch(videoUrl);
const videoArrayBuffer = await response.arrayBuffer();
const videoBuffer = Buffer.from(videoArrayBuffer);
const bucket = "my_bucket";
const objectKey = `video_${Date.now()}.mp4`;
await s3Client.send(
new PutObjectCommand({
Bucket: bucket,
Key: objectKey,
Body: videoBuffer,
})
);
logger.log(`Video uploaded to Supabase Storage bucket`, { objectKey });
return {
objectKey,
bucket: bucket,
};
},
});
Testing your task
To test this task in the dashboard, you can use the following payload:
{
"videoUrl": "<a-video-url>"
}
Learn more about Supabase and Trigger.dev
Full walkthrough guides from development to deployment
Task examples with code you can copy and paste