Final fix for upload API

This commit is contained in:
Manohar Gupta 2026-05-10 14:48:22 +05:30
parent 1fc52a0609
commit d2c7cee1e8

View file

@ -20,12 +20,10 @@ const client = new S3Client({
const baseUrl = `https://pub-37a76fd657c94d1dbc521a109c087a11.r2.dev/tia`; const baseUrl = `https://pub-37a76fd657c94d1dbc521a109c087a11.r2.dev/tia`;
// GET memories export async function GET() {
export async function GET(req: NextRequest) {
try { try {
const command = new ListObjectsV2Command({ Bucket: "tia" }); const command = new ListObjectsV2Command({ Bucket: R2.bucket });
const response = await client.send(command); const response = await client.send(command);
return NextResponse.json({ return NextResponse.json({
success: true, success: true,
count: response.Contents?.length || 0, count: response.Contents?.length || 0,
@ -41,7 +39,6 @@ export async function GET(req: NextRequest) {
} }
} }
// POST get upload URL
export async function POST(req: NextRequest) { export async function POST(req: NextRequest) {
let body; let body;
try { try {
@ -60,13 +57,12 @@ export async function POST(req: NextRequest) {
const key = `memories/${childId || "default"}/${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${ext}`; const key = `memories/${childId || "default"}/${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${ext}`;
const command = new PutObjectCommand({ const command = new PutObjectCommand({
Bucket: "tia", Bucket: R2.bucket,
Key: key, Key: key,
ContentType: contentType, ContentType: contentType,
}); });
const url = await getSignedUrl(client, command, { expiresIn: 3600 }); const url = await getSignedUrl(client, command, { expiresIn: 3600 });
return NextResponse.json({ return NextResponse.json({
uploadUrl: url, uploadUrl: url,
key, key,