-1

I'm using the basic unity firebase storage documentation provided by firebase.

Picture provided by firebase

after implementing the codes i get an error saying

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

after that i have changed the code as

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 use this it does not returns a string of that URL

It returns :

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

I need to get the string value of downloadURL of the image once it is uploaded. Please help.

Thank you in advance.

7
  • Because async returns a task, you need the result of the task. Commented Jul 31, 2019 at 10:06
  • yes, thank you.. But how do i get the url as a string ? Commented Jul 31, 2019 at 10:18
  • Possible duplicate of taskSnapshot.getDownloadUrl() is deprecated Commented Jul 31, 2019 at 10:21
  • The linked isnt necessarily firebased but its exactly the same problem and question Commented Jul 31, 2019 at 10:22
  • @BugFinder the question isn't primarily about DownloadUrl() but GetDownloadUrlAsync though Commented Jul 31, 2019 at 11:16

1 Answer 1

2

Like most of the firebase methods GetDownloadUrlAsync() as the name already says is async and returns a Task<Uri>.

just as before you should use ContinueWith()

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

where result will be of type Uri

Sign up to request clarification or add additional context in comments.

2 Comments

I still get the same result as System.Threading.Tasks.Task`1[System.Uri] in the console. I need the string value of this result which is the URL to download the Img.
sorry you have to use the Result of the task .. renamed it to make it clearer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.