【问题标题】:How to Upload File to Firebase Storage in .Net C# Windows Form?如何在 .Net C# Windows 窗体中将文件上传到 Firebase 存储?
【发布时间】:2019-06-26 10:51:12
【问题描述】:

我尝试了以下功能将图像上传到 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 对。" } }

【问题讨论】:

标签: c# winforms firebase firebase-storage


【解决方案1】:

您必须编辑您的 Bucket 变量。而不是使用gs://xxxxx.appspot.com/ 它应该只是xxxxx.appspot.com

【讨论】:

  • 很高兴知道它解决了您的问题!您能否将答案标记为解决方案?
  • 知道如何“窥视”或“读取”存储中已存在的文件吗?
猜你喜欢
  • 2015-12-03
  • 2020-04-08
  • 2016-07-04
  • 2014-05-14
  • 2016-11-05
  • 2018-06-21
  • 2019-02-10
  • 2019-03-26
  • 1970-01-01
相关资源
最近更新 更多