Back

.setKey is not a function && .listStorage is not a function

  • 0
  • Web
  • Storage
Loona
18 Nov, 2023, 20:01

Hi, I tried to create a listBuckets() function using your documentation. Unfortunately I have some errors, like for example that .setkey is supposedly not a function. When I remove this I am told that .listBuckets() is not a function. Please find attached the code. I am using nextjs 14.

TypeScript
import { Account, Storage, Client } from "appwrite";

const client = new Client();

client
    .setEndpoint('https://cloud.appwrite.io/v1')
    .setProject('my project id')
    .setKey('my api key')
;

async function listfolders () {
    const storage = new Storage(client);
    const promise = storage.listBuckets();

    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
}
TL;DR
The user is trying to use Appwrite's .listBuckets() function to get a list of buckets but is getting errors that .setKey() and .listBuckets() are not functions. They are using next.js. The solution is to use the server SDK and ensure that the code runs server-side.
Drake
18 Nov, 2023, 20:02

Yes, these methods are not available in the client SDK. Please see here for the difference between client and server SDKs: https://appwrite.io/docs/sdks

Loona
18 Nov, 2023, 20:03

Okay, thank you I will have a look into it!

Loona
18 Nov, 2023, 20:16

do you have an example on how I can use this function with next js?

Drake
18 Nov, 2023, 20:22

You would need to use the server SDK. It's a different package. Make sure it only runs server side

Loona
18 Nov, 2023, 20:43

Hmm, I currently have a project in which I am creating a front end for a 360 degree tour. I thought Appwrite is a good way to store this data, but I just realized myself that you can't create multiple subfolders. A 360 degree tour is created from several 360 degree images and then has the following folder structure: [project_name] -> /app-files /index.html i/mg (there will be all the controll icons be saved) /data.js /style.css /tiles (where the 360 degree photos will be stored) /0 /1 /2 ... for each room a new folder in which there is another folder in which there is another folder in which there is another folder in which the 360 degree pictures are stored In the Index.html you can see the complete 360 degree tour. I need a way to safely transfer the data between my backend server (if needed) and my front end where the index.html is then displayed.

Loona
18 Nov, 2023, 20:44

Do you know any good methods to implement this?

Loona
18 Nov, 2023, 20:45

I thought I could maybe make an api request in the frontend to my backend server, on which I then return the index.html in the api request

Drake
18 Nov, 2023, 22:02

For folder structure, I recommend creating a collection for your files and you can include metadata that you need. Maybe you could have a collection of rooms and each room document has a files attribute that's an array of file IDs

Uhh your index.html usually has little to do with the images ... usually you have an img element with a src attribute that's a URL. So, the browser, then fetches the file.

Loona
19 Nov, 2023, 09:15

Sorry, I think I expressed myself slightly unclear.

So I'll explain it again from the beginning :). There is a program with which you can create 360 degree tours. I implement this program with a frame on my website.

So now someone creates a 360 degree tour and saves it. This consists of a zip folder with: a js, css, metadata folder and an index.html.

I can display the 360 degree tour correctly in the browser via the index.html.

If, for example, this 360 degree tour is uploaded to my dashboard, I would like to store it securely (I had hoped that this could somehow be done via the AppWrite storage).

If it were only images, it would be clear how I could do it, via the storage and store the images in a database in an array, but since this is a whole folder that you can't really split up, it proves to be a challenge.

Drake
19 Nov, 2023, 14:16

If you weren't using Appwrite, how would you do this?

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