locked
Getting a download link of uploaded file (e.g image) Immediately after a Successful upload. RRS feed

  • Question

  • User387309 posted

    I am using a Firebase Storage Dotnet Library by Step-Up-Labs to Upload Images from Xamarin.Forms application to Firebase Storage. The Images succefully uploads without any error. But the Problem is that i have to use TWO Tasks. First Task Uploads Image to Firebase & Second one is to Get the Uploaded Image Download Link with Token. For Second Task i'm using a ENTRY to get Download Link. I want to Merge these Both tasks. In simple, I pick an image from gallery, then upload it to Firebase Storage . As soon as image Upload completes the Download Link Immediately Fetch & Shows in ENTRY . Below Is My Code So You Can easily Understand What i'm saying....

    using Firebase.Storage; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks;

    namespace WhatsLinks.Databases { public class FirebaseStorageHelper { FirebaseStorage firebaseStorage = new FirebaseStorage("");

        TASK 1
        public async Task<string> UploadImage(Stream fileStream, string fileName)
        {
            var imageUrl = await firebaseStorage
                .Child("UserImages")
                .Child(fileName)
                .PutAsync(fileStream);
            return imageUrl;
        }
    
        TASK 2
        public async Task<string> GetImageFile(string fileName)
        {
            return await firebaseStorage
                .Child("UserImages")
                .Child(fileName)
                .GetDownloadUrlAsync();
        }
    }
    

    }

    Wednesday, January 29, 2020 1:59 PM

Answers

  • User369979 posted

    public async Task<string> UploadImage(Stream fileStream, string fileName) this method is an awaitable one. We could use await symbol to wait for its completion like:

    var result = await UploadImage(stream, fileName);
    // After that we could set the text value of your entry
    yourEntry.Text = result;
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, January 31, 2020 9:50 AM

All replies

  • User3516 posted

    As far as i understand your code the imageUrl in your first task shoul contain the download link to your uploaded image.

    Wednesday, January 29, 2020 2:07 PM
  • User387309 posted

    @DirkWilhelm said: As far as i understand your code the imageUrl in your first task shoul contain the download link to your uploaded image.

    Can You Please Explain Further ?

    Wednesday, January 29, 2020 2:30 PM
  • User3516 posted
    public async Task<string> UploadImage(Stream fileStream, string fileName)
        {
            var imageUrl = await firebaseStorage
                .Child("UserImages")
                .Child(fileName)
                .PutAsync(fileStream);
            return imageUrl;   //<-- this is your download link
        }
    
    Wednesday, January 29, 2020 2:33 PM
  • User387309 posted

    @DirkWilhelm said: public async Task UploadImage(Stream fileStream, string fileName) { var imageUrl = await firebaseStorage .Child("UserImages") .Child(fileName) .PutAsync(fileStream); return imageUrl; //<-- this is your download link }

    Then brother What is this in Second Task .GetDownloadUrlAsync() ?

    Wednesday, January 29, 2020 2:36 PM
  • User3516 posted

    It is a method to get the download url incase you just have the name of a previous uploaded file?

    What does the dovuemntation of that library say?

    Did you take a look at the result of your first task?

    Wednesday, January 29, 2020 2:41 PM
  • User387309 posted

    Please take a look at attached image. Through Task 1 i upload the image to Firebase storage and through Second Step I'm Fethching The Downloadable Link Which shows in Entry . This occurs through entering the image name in entry with full path i.e image.jpg. But this is the second step . Iwant to merge both these into only one step


    Wednesday, January 29, 2020 2:51 PM
  • User369979 posted

    I'm also confused about what you want to achieve. The task 2 is used for retrieving the download url in case you knew the file name. If you want to get the current download url of the uploading image the first task has return. There's no need to call the task 2 to retrieve it again.

    Thursday, January 30, 2020 10:29 AM
  • User387309 posted

    @LandLu said: I'm also confused about what you want to achieve. The task 2 is used for retrieving the download url in case you knew the file name. If you want to get the current download url of the uploading image the first task has return. There's no need to call the task 2 to retrieve it again.

    Brother You Have Totally Understand my Problem ... Yes the task is returning a Link, but i'm facing a problem how to display this returning link in a ENTRY or in a Display Alert Immediately after successful Image Upload... Due to this , Unfortunately I have to Use another Task which Gets the Download Link of a Specific Image the name of which i Knows. But i want to End the headache of giving a image name and then URL fetch............ o:) "Pick Image, Upload Image and Immediately Get Download Url"

    Thursday, January 30, 2020 3:25 PM
  • User369979 posted

    public async Task<string> UploadImage(Stream fileStream, string fileName) this method is an awaitable one. We could use await symbol to wait for its completion like:

    var result = await UploadImage(stream, fileName);
    // After that we could set the text value of your entry
    yourEntry.Text = result;
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, January 31, 2020 9:50 AM
  • User387309 posted

    Thakns For Your Cooperation. Especially @LandLu. <3

    Friday, January 31, 2020 10:27 AM