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`;
// GET memories
export async function GET(req: NextRequest) {
export async function GET() {
try {
const command = new ListObjectsV2Command({ Bucket: "tia" });
const command = new ListObjectsV2Command({ Bucket: R2.bucket });
const response = await client.send(command);
return NextResponse.json({
success: true,
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) {
let body;
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 command = new PutObjectCommand({
Bucket: "tia",
Bucket: R2.bucket,
Key: key,
ContentType: contentType,
});
const url = await getSignedUrl(client, command, { expiresIn: 3600 });
return NextResponse.json({
uploadUrl: url,
key,