nhost / nhost-dart

Nhost Dart & Flutter packages
https://nhost.io
MIT License
91 stars 33 forks source link

No method to get public file URL from Storage #80

Closed vipafattal closed 2 years ago

vipafattal commented 2 years ago

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!

marcusrohden commented 2 years ago

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

MaxSchilling commented 2 years ago

👀 Following - will need the functionality as well!

vipafattal commented 2 years ago

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