Back

[SOLVED] How to use Storage Listfiles of appwrite

  • 0
  • Web
Ayush
24 Jun, 2023, 10:48
TypeScript
        const fileId = generateFileId(locationName);
        const promise = storage.listFiles('6496afb137df9de6ce7b', fileId);
        promise
          .then((response) => {
            console.log('Place images retrieved successfully:', response);
            setPlaceImages(response.files);
          })
          .catch((error) => {
            console.error('Failed to retrieve place images:', error);
            // Handle the error
          });
      };
    useEffect(() => {
        retrievePlaceImages();
      }, []);```
TL;DR
The user was experiencing an error when using the `listFiles` function of the Appwrite Storage feature. They initially tried using `getFilePreview` and `getFile` but the issue persisted. They then added a try/catch block and made the function asynchronous. However, the error still persisted. They mentioned that they are using Appwrite Cloud and asked for help in removing the error. The last code provided shows that the function was not using async/await and catch but instead using promise/then and catch. No solution is provided in the thread.
Ayush
24 Jun, 2023, 10:55

please help me remove the error

Ayush
24 Jun, 2023, 10:56

Failed to retrieve place images: AppwriteException: Server Error at Client.<anonymous>

Ayush
24 Jun, 2023, 15:33

Promise.then() dosen't returns response it goes straight away into catch block

Drake
24 Jun, 2023, 17:25

You're using cloud?

Also, why not use async/try/await/catch rather than callbacks?

Ayush
24 Jun, 2023, 17:31

till now things were working i copy pasted from docs so

Ayush
24 Jun, 2023, 17:33

okay I am changing this to async/try/catch and if error persists i would let you know

Ayush
24 Jun, 2023, 17:40

hey steven error persists even after this

Ayush
24 Jun, 2023, 17:40
Ayush
24 Jun, 2023, 17:40
TypeScript
        try {
          const fileId = generateFileId(locationName);
          console.log("retrievePlaceImages fileId: ", fileId);
      
          const response = await storage.listFiles('6496afb137df9de6ce7b', fileId);
          console.log('Place images retrieved successfully:', response);
          setPlaceImages(response.files);
        } catch (error) {
          console.error('Failed to retrieve place images:', error);
          // Handle the error
        }
      };
      
      useEffect(() => {
        retrievePlaceImages();
      }, []);```
Ayush
24 Jun, 2023, 17:46

@Steven updated to try catch block

Drake
24 Jun, 2023, 17:59

There are additional queries being passed 🧐

Drake
24 Jun, 2023, 17:59

Perhaps you should be using get file instead

Drake
24 Jun, 2023, 18:02

Or get file for view

Ayush
24 Jun, 2023, 21:18

my issue has got resolved with getFilePreview

Ayush
24 Jun, 2023, 21:18

Thanks Steven 😊

Ayush
24 Jun, 2023, 21:18

@Steven

Ayush
24 Jun, 2023, 21:19

ya there are

Drake
24 Jun, 2023, 21:37

[SOLVED] How to use Storage Listfiles of appwrite

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more