Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

Add public download url of the asset in StorageResponse #25

Closed
paurakhsharma opened this issue Jun 12, 2021 · 7 comments
Closed

Add public download url of the asset in StorageResponse #25

paurakhsharma opened this issue Jun 12, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@paurakhsharma
Copy link

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.
@paurakhsharma paurakhsharma added the enhancement New feature or request label Jun 12, 2021
@dshukertjr
Copy link
Member

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!

@paurakhsharma
Copy link
Author

@dshukertjr That sounds awesome. Looking forward to it 😍

@phamhieu
Copy link
Member

@paurakhsharma, you can find the new public url feature on the latest version https://pub.dev/packages/supabase

@paurakhsharma
Copy link
Author

@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?

@phamhieu
Copy link
Member

phamhieu commented Jun 22, 2021

@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
Screenshot 2021-06-22 at 9 26 20 AM

@dshukertjr
Copy link
Member

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!

@paurakhsharma
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants