Unity - How to get download URL after uploading image to Firebase Storage?


Ariane Madan

I am using the basic unity firebase provided by firebase to store documents.

Image courtesy of firebase

After executing the code, I get an error message

'StorageMetadata.DownloadUrl' is deprecated: 'StorageMetadata.DownloadUrl' is deprecated. Please use StorageReference.GetDownloadUrlAsync()' instead (CS0619) [Assembly-CSharp]

After that I changed the code to

string download_url = storage_ref.Child("ss.jpg").GetDownloadUrlAsync().ToString();

in my code

images_ref.PutFileAsync(local_file).ContinueWith((Task<StorageMetadata> task) =>
{
    if(task.IsFaulted || task.IsCanceled)
    {
        Debug.Log(task.Exception.ToString());
        status.text = "Uo-oh, an error occurred!";
    }
    else
    {
        // Metadata contains file metadata such as size, content-type, and download URL.
        Firebase.Storage.StorageMetadata metadata = task.Result;
        Debug.Log("Finished uploading...");

        //string download_url = metadata.DownloadUrl.ToString(); // This shows error

        //Changed as
        string download_url = storage_ref.Child("ss.jpg").GetDownloadUrlAsync().ToString();
        Debug.Log("download url = " + download_url);
    }
});

But when using it it doesn't return the string for that URL

it returns:

下载 url = System.Threading.Tasks.Task`1[System.Uri]

After uploading, I need to get the string value of the image's downloadURL. please help.

Thank you in advance.

Hugo

Like most firebase methods the name already says , it returns a .GetDownloadUrlAsync()asyncTask<Uri>

As before, you should useContinueWith()

storage_ref.Child("ss.jpg").GetDownloadUrlAsync().ContinueWith((Task<Uri> uriTask) => 
{
    string download_url = uriTask.Result.ToString();
    Debug.Log(download_url);
});

where resultwill typeUri

Related


@react-native-firebase/storage - get url after uploading image

James Murphy I'm trying to find an efficient way to get the url of an image in firebase right after ive upload. I would like to avoid writing a completely separate function for this. And I want to include it in the Promise chain. see code below import storage

@react-native-firebase/storage - get url after uploading image

James Murphy I'm trying to find an efficient way to get the url of an image in firebase right after ive upload. I would like to avoid writing a completely separate function for this. And I want to include it in the Promise chain. see code below import storage

@react-native-firebase/storage - get url after uploading image

James Murphy I'm trying to find an efficient way to get the url of an image in firebase right after ive upload. I would like to avoid writing a completely separate function for this. And I want to include it in the Promise chain. see code below import storage

@react-native-firebase/storage - get url after uploading image

James Murphy I'm trying to find an efficient way to get the url of an image in firebase right after ive upload. I would like to avoid writing a completely separate function for this. And I want to include it in the Promise chain. see code below import storage

@react-native-firebase/storage - get url after uploading image

James Murphy I'm trying to find an efficient way to get the url of an image in firebase right after ive upload. I would like to avoid writing a completely separate function for this. And I want to include it in the Promise chain. see code below import storage

How to get image uri after uploading image to firebase storage?

Can I'm working on a kotlin project that requires the user to insert an image using the camera or gallery, then the app will upload the image to Firebase storage and save the image uri to FireStore. After that I use glide to get all images and display it using

How to get image uri after uploading image to firebase storage?

Can I'm working on a kotlin project that requires the user to insert an image using the camera or gallery, then the app will upload the image to Firebase storage and save the image uri to FireStore. After that I use glide to get all images and display it using