Add public download url of the asset in StorageResponse
paurakhsharma opened this issue ยท 7 comments
First of all, Thank you for this amazing project.
Feature request
- Add an option to get the public download URL for the uploaded asset just like firebase storage.
Is your feature request related to a problem? Please describe.
- Currently, when I upload the asset to my storage I need to save the relative path of the asset in the database and download the file when I need to show it in the Flutter app.
- This is a problem especially when I need to show an image to a user as I cannot directly use it as a Network Image.
Describe the solution you'd like
- Ability to get the public URL of the file (just like the one I can copy from the storage console) from the upload response.
Describe alternatives you've considered
Currently, I use a future builder to download the image and show it to the user.
Future<dynamic> downloadImage(String imagePath) {
return _client.storage.from('journalImages').download(imagePath);
}
FutureBuilder(
future: downloadImage(imagePath),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (!snapshot.hasData)
return Center(
child: CircularProgressIndicator(),
);
return Image.memory(
snapshot.data.data,
height: height,
);
},
)
Additional context
- If this feature is lacking in the Supabase itself, I can move this issue to Supabase project.
Thanks @paurakhsharma for opening an issue!
Method to get public URL landed on supabase-js recently.
supabase/storage-js#10
I can try to get this implemented this weekend!
@dshukertjr That sounds awesome. Looking forward to it ๐
@paurakhsharma, you can find the new public url feature on the latest version https://pub.dev/packages/supabase
@dshukertjr @phamhieu
I am having some problem getting it to work, maybe I am missing something here:
Here is my code to get the publicUrl
Future<String?> uploadImage(PlatformFile file) async {
final fileName = '${DateTime.now().toString()}_${file.name}';
final response = await _client.storage.from('journalImages').upload(
fileName,
File(file.path!),
);
if (response.data == null) return null;
final downloadUrl =
_client.storage.from('journalImages').getPublicUrl(fileName).data;
print(downloadUrl);
return downloadUrl;
This the the URL that gets printed out: https://dlrvdojpksbdmvnygpeb.supabase.co/storage/v1/object/public/journalImages/2021-06-22%2007:58:17.902992_IMG_0005.jpeg
But it returns 404.
Anything I am missing?
@paurakhsharma can you check on your supabase project dashboard if journalImages
is a public bucket? You can also copy the image public url on the dashboard and compare with generated version from the client. The generated url looks valid to me.
maybe you can try to rename your folder to use Only lowercase letters
Hey @paurakhsharma !
By default all buckets created in Supabase are private. You can go into your Supabase console's storage setting and make buckets public!
Thanks, @dshukertjr, and @phamhieu for the quick response.
Yes, my bucket wasn't set to public. Setting it to public worked like a charm ๐
Many thanks.