From 1dd8563450e45d2db1861ea24c35b0e0fc368045 Mon Sep 17 00:00:00 2001 From: Mannu Date: Sun, 10 May 2026 15:01:53 +0530 Subject: [PATCH] Debug: list buckets first --- src/app/api/upload/route.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/api/upload/route.ts b/src/app/api/upload/route.ts index 183b81d..05f9427 100644 --- a/src/app/api/upload/route.ts +++ b/src/app/api/upload/route.ts @@ -1,4 +1,4 @@ -import { S3Client, PutObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3"; +import { S3Client, PutObjectCommand, ListObjectsV2Command, ListBucketsCommand } from "@aws-sdk/client-s3"; import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; import { NextRequest, NextResponse } from "next/server"; @@ -18,14 +18,31 @@ const client = new S3Client({ }, }); +const clientNoBucket = new S3Client({ + region: "auto", + endpoint: `https://${R2.accountId}.r2.cloudflarestorage.com`, + credentials: { + accessKeyId: R2.accessKeyId, + secretAccessKey: R2.secretKey, + }, +}); + const baseUrl = `https://pub-37a76fd657c94d1dbc521a109c087a11.r2.dev/tia`; export async function GET() { try { - const command = new ListObjectsV2Command({ Bucket: R2.bucket }); + // First try listing buckets + const bucketsCmd = new ListBucketsCommand({}); + const bucketsRes = await clientNoBucket.send(bucketsCmd); + console.log("Buckets:", bucketsRes.Buckets); + + // Then list objects in "tia" bucket + const command = new ListObjectsV2Command({ Bucket: "tia" }); const response = await client.send(command); + return NextResponse.json({ success: true, + buckets: bucketsRes.Buckets, count: response.Contents?.length || 0, items: response.Contents?.map((o) => ({ key: o.Key,