A Next.js 14 application delivering the creator β upload β library β play loop with authentication, Prisma/Postgres, S3-compatible storage, search, and analytics.
41a1d8d
verified
| ```typescript | |
| import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3" | |
| import { v4 as uuidv4 } from "uuid" | |
| const s3Client = new S3Client({ | |
| endpoint: process.env.S3_ENDPOINT, | |
| region: process.env.S3_REGION, | |
| credentials: { | |
| accessKeyId: process.env.S3_ACCESS_KEY, | |
| secretAccessKey: process.env.S3_SECRET_KEY, | |
| }, | |
| }) | |
| export async function uploadFile(file: File) { | |
| const fileKey = `tracks/${uuidv4()}${file.name}` | |
| await s3Client.send( | |
| new PutObjectCommand({ | |
| Bucket: process.env.S3_BUCKET_NAME, | |
| Key: fileKey, | |
| Body: Buffer.from(await file.arrayBuffer()), | |
| }) | |
| ) | |
| return fileKey | |
| } | |
| ``` |