我尝试了以下功能将图像上传到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对。” } }
答案 0 :(得分:0)
您必须编辑Bucket
变量。不应使用gs://xxxxx.appspot.com/
,而应仅使用xxxxx.appspot.com
答案 1 :(得分:0)
这里有一个代码,可以帮助您在实时数据库中加载base64格式的图像。我会给你链接,很快再见。
How to upload a pdf file to google storage using visual C #?