[英]How to Upload File to Firebase Storage in .Net C# Windows Form?
我嘗試了以下功能將圖像上傳到 Firebase 存儲
private async void UploadFiles()
{
var stream = File.Open(@"D:\\Capture.png", FileMode.Open);
var auth = new FirebaseAuthProvider(new FirebaseConfig(ApiKey));
var a = await auth.SignInWithEmailAndPasswordAsync(AuthEmail, AuthPassword);
var cancellation = new CancellationTokenSource();
var task = new FirebaseStorage(
Bucket,
new FirebaseStorageOptions
{
AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken),
ThrowOnCancel = true // when you cancel the upload, exception is thrown. By default no exception is thrown
})
.Child("receipts")
// .Child("test")
.Child("Capture.png")
.PutAsync(stream, cancellation.Token);
task.Progress.ProgressChanged += (s, e) => textBox1 .Text =($"Progress: {e.Percentage} %");
// cancel the upload
// cancellation.Cancel();
try
{
// error during upload will be thrown when you await the task
textBox1 .Text =("Download link:\n" + await task);
}
catch (Exception ex)
{
MessageBox .Show( ex.Message);
}
}
給我這個錯誤:
處理請求時發生異常。 網址: https ://firebasestorage.googleapis.com/v0/b/gs: //testingsupport-44f0b.appspot.com//o? name = receipts% 2FCapture.png響應:{“錯誤”:{“代碼”: 400, "message": "無效的 HTTP 方法/URL 對。" } }
您必須編輯您的Bucket
變量。 而不是使用gs://xxxxx.appspot.com/
它應該只是xxxxx.appspot.com
在這里,我有一個代碼可以幫助您在實時數據庫中加載 base64 格式的圖像。 我給你鏈接,一會兒見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.