nhost / nhost-dart

Nhost Dart & Flutter packages

Home Page:https://nhost.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No method to get public file URL from Storage

vipafattal opened this issue · comments

How to get a public URL if we want to download a file manually without using the functions storage.downloadFile or storage.downloadImage, Something like getPublicUrl in the storage.

At the same time, I tried to use the getPresignedUrl from storage with Nhost running from CLI but I'm keep getting an error ERR_CONNECTION_REFUSED

Thank You!

I'm also with the same issue. I'm trying to get the url to use caching packages such as CachedNetworkImage. In case it is not possible, has anyone found any caching solution for image files? thank you

commented

👀 Following - will need the functionality as well!

I managed to create getPublicUrl function and it's simple.

Looking for the javascript implement for storage client:

 getPublicUrl(params: StorageGetUrlParams): string {
    const { fileId } = params
    return `${this.url}/files/${fileId}`
 }

As you can see from the code above, it's as simple as

final fileUrl =  "{STORAGE_URL}/files/{FILE_ID}";

Please note to be able to access the file publicly without auth you need to have a public role with select permission. For me, I created a public role that allows selection only on images mime_type just like below

image