Next.js Discord

Discord Forum

Not getting items from Appwrite Storage.

Unanswered
American Kestrel posted this in #help-forum
Open in Discord
American KestrelOP
I have a route.js file import { IFetchResponse, IFileData } from "@/types/types";
import { NextResponse } from "next/server";

export async function GET(){
const response = await fetch('https://cloud.appwrite.io/v1/storage/buckets/65d60da739219adc60eb/files', {
headers: {
'X-Appwrite-Project': '65d5fae96d83b9aa3bfe',
'Content-Type': 'application/json',
},
// next: { revalidate: 1}

})

if (!response.ok) {
//study about the error.js
throw new Error('Failed to fetch')
}


const res:IFetchResponse = await response.json()

// const id:IFileData[] = res[0].files
return Response.json({res});
}
When i access it in browser /api/hero
I am getting a single file as screen shot of the browser window attached below
but i have two files in the storage
The post man response with the same endpoint is
{
"total": 2,
"files": [
{
"$id": "65dd787c23607504be0c",
"bucketId": "65d60da739219adc60eb",
"$createdAt": "2024-02-27T05:51:56.449+00:00",
"$updatedAt": "2024-02-27T05:51:56.449+00:00",
"$permissions": [
"read("user:65cc6c71465df58985ba")",
"update("user:65cc6c71465df58985ba")",
"delete("user:65cc6c71465df58985ba")"
],
"name": "pat-taylor-12V36G17IbQ-unsplash.jpg",
"signature": "4b2cf4435d3e17345a24468d6f03a4c5",
"mimeType": "image/jpeg",
"sizeOriginal": 821038,
"chunksTotal": 1,
"chunksUploaded": 1
},
{
"$id": "65e1787187712fbab6f0",
"bucketId": "65d60da739219adc60eb",
"$createdAt": "2024-03-01T06:40:49.853+00:00",
"$updatedAt": "2024-03-01T06:40:49.853+00:00",
"$permissions": [
"read("user:65cc6c71465df58985ba")",
"update("user:65cc6c71465df58985ba")",
"delete("user:65cc6c71465df58985ba")"
],
"name": "dumbbells-2465478_640.jpg",
"signature": "7d2f2cdc5e31f9c0d9696faffe304fa5",
"mimeType": "image/jpeg",
"sizeOriginal": 90883,
"chunksTotal": 1,
"chunksUploaded": 1
}
]
}Which is giving me both the files.Could you pls suggest me a solution?

0 Replies