C# Upload PDF Files into Firebase Project Storage?
Asked Answered
F

2

5

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.

Foist answered 1/12, 2016 at 14:10 Comment(3)
The current release of Firebase for Unity (which is our only c# client) does not yet support Storage. In addition, Firebase Storage does not have a REST api and I believe the library you reference is for the previous version of the Firebase Realtime Database that did not have Storage support. Can you confirm you are looking for Unity support? Or are you looking for C# support on another platform?Goldwin
Im only looking for a C# Support for Visual Studio to upload files to the Firebase Storage of my Project. Im not searching for Unity. I know that Unity got a official support for Firebase. So if there isnt any REST Api for the Storage i can do nothing? And yeah the library i have referenced is for previous versions of Firebase and doesnt have Storage support either.Foist
Firebase Storage is equivalent to Google Cloud Storage, but adds support for 3rd party auth + rules. If you are running in a secure environment and can use a service account, try looking at our c# GCS libraries: github.com/GoogleCloudPlatform/google-cloud-dotnetGoldwin
T
9

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.

Tremolant answered 5/1, 2017 at 12:54 Comment(2)
this throws 403 Permission denied, could you please add how to authenticate the client which performs uploading.Pay
youtu.be/SpxHVrpfGgU?t=370 here is the general-purpose explanation from the official youtube channel for the 403 error.Negotiable
D
0

if you have a private key generated from your clound App Account you may use it for secure auth with storage,FireStorage,FCM...etc as mentioned in Admin SDK. For auth uploading

using Google.Apis.Auth.OAuth2;
using Google.Apis.Storage.v1;
using Google.Cloud.Storage.V1;

 string privateKeypath = @"../Resources/private_key.json";

//Create a storage client and scope in to CloudPlatForm

var storageClient = StorageClient.Create( GoogleCredential.FromFile(privateKeypath)
.CreateScoped(StorageService.ScopeConstants.CloudPlatform));

// parameter: bucket name, fileName , contentType
var uploadUri = await storageClient.InitiateUploadSessionAsync("bucket_Name.appspot.com","Pro/ok2.jpg","image/jpeg",null);

var uploadInstant = Google.Apis.Upload.ResumableUpload.CreateFromUploadUri(uploadUri, StreamData);
await uploadInstant.UploadAsync();
       
        
       
Dado answered 20/8, 2024 at 10:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.