如何在.Net C# Windows Form中上传文件到Firebase存储?

3
我尝试了以下函数将图片上传到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);
        }
    }

获取此错误信息:
处理请求时发生异常。 URL:https://firebasestorage.googleapis.com/v0/b/gs://testingsupport-44f0b.appspot.com//o?name=receipts%2FCapture.png 响应:{ "error": { "code": 400, "message": "无效的HTTP方法/URL对。" } }

在上述代码中,我正在使用Firebase Storage.net:https://github.com/step-up-labs/firebase-storage-dotnet - Isaac Be
1个回答

2

您需要编辑您的Bucket变量。不要使用gs://xxxxx.appspot.com/,而应该只使用xxxxx.appspot.com


很高兴知道它解决了你的问题!你能把答案标记为解决方案吗? - apenasVB
有没有想过如何“查看”或“读取”已经存储在存储器上的文件? - Yafim Simanovsky

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接