Back

How to get URL of stored file in appwrite storage ?

  • 2
  • Self Hosted
  • Storage
vikramsamak
5 Nov, 2023, 04:26

I want to get url of stored file and use it in document while storing it in database ...

TypeScript
       const storedPhotoDetails = await storage.createFile(
           'bucket-id',
           uuidv4(),
           InputFile.fromBuffer(photobuffer, photo.name))
    // Get URL of stored file 
       try {
      const storage_url = await storage.getFile(
               'bucket-id',
               storedPhotoDetails.$id)
           console.log(storage_url)
       } catch (error) {
           console.log(error)
       }```js
TL;DR
To get the URL of a stored file in Appwrite storage, you will need to build the URL manually. You can refer to the web SDK documentation for guidance on how to do this. Currently, there is no method provided by Appwrite SDKs to directly generate the URL. However, there is a feature request for this functionality on GitHub that you can support if you're interested. In the meantime, you can use the `createFile` method to store the file in a bucket and then use the `getFile` method to retrieve the URL of the stored file.
Drake
5 Nov, 2023, 05:29

Is this with the web sdk? Or node?

vikramsamak
5 Nov, 2023, 06:37

No I m using server SDK (in Next js project)

vikramsamak
5 Nov, 2023, 06:38

Node

Drake
5 Nov, 2023, 17:15

You would need to build the url manually. See the web sdk: https://github.com/appwrite/sdk-for-web/blob/ca4ef6dd0f8d7110db57f8b3b295ce62e629eec5/src/services/storage.ts#L314

We plan to introduce methods for building the url in all SDKs, but we haven't had time to focus on it. If you're interested in the feature, make sure to 👍 https://github.com/appwrite/sdk-generator/issues/557

vikramsamak
5 Nov, 2023, 17:19

Thanks @Steven

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