Working upload, list has issues
This commit is contained in:
parent
1dd8563450
commit
cf5ea7b820
1 changed files with 2 additions and 18 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { S3Client, PutObjectCommand, ListObjectsV2Command, ListBucketsCommand } from "@aws-sdk/client-s3";
|
||||
import { S3Client, PutObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3";
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
|
|
@ -18,31 +18,15 @@ 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 {
|
||||
// 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 command = new ListObjectsV2Command({ Bucket: R2.bucket });
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue