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 unable to get the file URL directly from Appwrite bucket using the file ID. The solution is to construct the URL manually from the metadata provided. Here is an example code snippet: ``` const fileUrl = `${config.endpoint}/storage/buckets/${config.appwriteFilesId}/files/${file.$id}/view`; ```
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`;

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