Reputation:
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.
Upvotes: 5
Views: 9677
Reputation: 19
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();
Upvotes: 0
Reputation: 1499
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.
Upvotes: 9