Search code examples
c#filefirebasefirebase-storage

C# Upload PDF Files into Firebase Project Storage?


Do you guys know how to upload PDF Files directly to a Firebase Project Storage? I searched a lot on the Internet but I found nothing.

Are there some librarys for C#? Or is there any Documentation for C# and Firebase?

Please help guys! Thanks

EDIT:

Ok I found a library: FirebaseSharp.

https://github.com/bubbafat/FirebaseSharp

But this Lib only supports previous versions of Firebase and doesnt have Storage Support either.


Solution

  • Try FirebaseStorage.net library.

    Here's a sample usage:

    // Get any Stream - it can be FileStream, MemoryStream or any other type of Stream
    var stream = File.Open(@"C:\Users\you\file.png", FileMode.Open);
    
    // Construct FirebaseStorage, path to where you want to upload the file and Put it there
    var task = new FirebaseStorage("your-bucket.appspot.com")
        .Child("data")
        .Child("random")
        .Child("file.png")
        .PutAsync(stream);
    
    // Track progress of the upload
    task.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %");
    
    // await the task to wait until upload completes and get the download url
    var downloadUrl = await task;
    

    There is also a related blog post.