Skip to content
Back

Can't get file URL from appwrite bucket with file ID

  • 0
  • React Native
  • Cloud
SorryLad2
1 Dec, 2024, 22:41

I was trying to decipher the documentation on this, anyone know how to get the file url? I am doing something like this and am getting the file.$id, but then when I try to get that json, it is empty. Do I need to create a new storage object or something?

TypeScript
// Upload the file to Appwrite Storage
    const file = await storage.createFile(
      config.appwriteFilesId, // Your Appwrite bucket ID
      ID.unique(), // Use unique() for unique ID generation
      inputFile // Upload the file buffer
    );

    console.log("File uploaded successfully. File ID:", file.$id);

    // Get the URL of the uploaded file
    const fileView = await storage.getFile(config.appwriteFilesId, file.$id);
TL;DR
Developers are having trouble getting the file URL from an Appwrite bucket with the file ID. The solution involves constructing the file URL manually from the metadata provided by Appwrite. Instead of relying on Appwrite to generate the file URL, developers can create it themselves using the endpoint and specific details from the metadata.
SorryLad2
1 Dec, 2024, 22:49

think I figured this out: appwrite doesn't give you the full url, you have to construct it yourself from the metadata provided. You can do something like this:

const fileUrl = ${config.endpoint}/storage/buckets/${config.appwriteFilesId}/files/${file.$id}/view`;

Axistro
2 Dec, 2024, 03:15

No, I think appwrite do gives a file url. Can you console log the fileurl variable?

Axistro
2 Dec, 2024, 03:16

And can you share What kind of permission have you setup for your storage bucket?

Axistro
2 Dec, 2024, 03:32

use this method storage.getFileView("bucket id","file id")

Joshi
2 Dec, 2024, 03:40

You do only get the fileUrl when using the web sdk

Axistro
2 Dec, 2024, 04:21

why am i getting one?

Axistro
2 Dec, 2024, 04:21

I am also on react native

Axistro
2 Dec, 2024, 04:22

Mine works

Axistro
2 Dec, 2024, 04:24
SorryLad2
2 Dec, 2024, 04:41

Idk building my own works fine so stuck with that

Axistro
2 Dec, 2024, 04:45

that is kind of inconvenient. Although I also did this when I was making the first app and you dont want to build your link again and again do you? in future project?

Axistro
2 Dec, 2024, 04:46

just sayin Get fileView works so why not use it 🤷‍♂️

Joshi
2 Dec, 2024, 05:45

Yeah you're right

ArnabChatterjee20k
2 Dec, 2024, 06:55

I achieved it with server + client sdk https://github.com/ArnabChatterjee20k/devsoc-gamenvt-ticket/tree/main/src/lib

Check the client and the server file for uploads

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