1

I have an UploadTask to send an image to Firebase Storage and it works but now I want to get the respective download URL but I'm facing some issues.

var upload = childRef.DownloadURL;

upload.AddOnSuccessListener(this);

I'm implementing the IOnSuccessListener interface so the function has to be:

public void OnSuccess(Java.Lang.Object result){
   //get url from result
}

How can I cast the result to access the URL?

  • Possible duplicate of [Get Download URL from file uploaded with Cloud Functions for Firebase](https://stackoverflow.com/questions/42956250/get-download-url-from-file-uploaded-with-cloud-functions-for-firebase)? – York Shen Jun 09 '17 at 07:14
  • It's the same ideia but with Javascript. I'm using Xamarin.Android and things are a little bit different. – rafaelqfigueiredo Jun 09 '17 at 09:28

5 Answers5

1

I got a solution in debugging mode

i saw the downloadurl's properties and found the Scheme and SchemeSpecificPart

Scheme = "https"

SchemeSpecificPart = "//firebasestorage.googleapis.com/v0/b/maplog-e4ba5.appspot.com/o/-L0AMbihF23YKxsL1uss?alt=media&token=5c7ccef1-c857-4982-a288-fded2f0ff1aa"

so here is my code:

void IOnSuccessListener.OnSuccess(Java.Lang.Object result)
{
    var snapShot = (UploadTask.TaskSnapshot)result;
    string imgUrl = snapShot.DownloadUrl.Scheme 
    + ":" 
    + snapShot.DownloadUrl.SchemeSpecificPart;
}

and it works! i was looking for the solution :(( but i finally found it myself XD

Community
  • 1
  • 1
yuweiwei
  • 56
  • 1
  • 3
0

I'm having the same issue, but was able to catch the error when adding the AddOnFailureListener. The error message wasn't helpful.

An unknown error occurred, please check the HTTP result code and inner exception for server response.

The result code was 0. The error code as -13000, which is an unknown error according to Firebase error table.

   FirebaseApp.InitializeApp(Application.Context);
   FirebaseStorage storage = FirebaseStorage.Instance;
   StorageReference storageRef = storage.GetReferenceFromUrl("gs://");
   StorageReference imageRef = storageRef.Child("folder/image.jpg");

   var downloadURL = imageRef.DownloadUrl.AddOnSuccessListener(this, this).AddOnFailureListener(this, this);

    public void OnSuccess(Java.Lang.Object result)
    {

        string downloadURL = result.ToString();
    }
    public void OnFailure(Java.Lang.Exception e)
    {
        Log.Warn("FirebaseStorage", "Download Failure", e);
    }
Vahe Tshitoyan
  • 1,439
  • 1
  • 11
  • 21
0

I had the same issue of the error code as -13000 which is an unknown error according to Firebase error table , i resolved by updating the playstore app in the device

Jayapen Jose
  • 55
  • 1
  • 7
0

I would say EncodedSchemeSpecificPart worked perfect for me

        var snapShot = (UploadTask.TaskSnapshot)result;
        string downloadURL =snapShot.DownloadUrl.Scheme + ":" +snapShot.DownloadUrl.EncodedSchemeSpecificPart;
Jayapen Jose
  • 55
  • 1
  • 7
0

For the latest Xamarin Android this is the correct answer

public async void OnSuccess(Java.Lang.Object result)
{
    var snapShot = (UploadTask.TaskSnapshot)result;

    if (snapShot != null)
    {
        var url = await snapShot.Storage.GetDownloadUrlAsync();
        imageUrl = url?.ToString();
    }
}
sabsab
  • 1,073
  • 3
  • 16
  • 30