简体   繁体   English

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

[英]How to Upload File to Firebase Storage in .Net C# Windows Form?

I Tried the Following Function to upload an image to Firebase Storage我尝试了以下功能将图像上传到 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);
        }
    }

Get me this error :给我这个错误:

Exception occured while processing the request.处理请求时发生异常。 Url: https://firebasestorage.googleapis.com/v0/b/gs://testingsupport-44f0b.appspot.com//o?name=receipts%2FCapture.png Response: { "error": { "code": 400, "message": "Invalid HTTP method/URL pair."网址: https ://firebasestorage.googleapis.com/v0/b/gs: //testingsupport-44f0b.appspot.com//o? name = receipts% 2FCapture.png响应:{“错误”:{“代码”: 400, "message": "无效的 HTTP 方法/URL 对。" } } } }

You have to edit your Bucket variable.您必须编辑您的Bucket变量。 Instead of using gs://xxxxx.appspot.com/ it should be only xxxxx.appspot.com而不是使用gs://xxxxx.appspot.com/它应该只是xxxxx.appspot.com

here I have a code that can help you load an image in base64 format in realtime database.在这里,我有一个代码可以帮助您在实时数据库中加载 base64 格式的图像。 I'll give you the link see you soon.我给你链接,一会儿见。

How to upload a pdf file to google storage using visual C #? 如何使用visual C#将pdf文件上传到谷歌存储?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将txt或csv文件上传到windows表单c# - how to Upload a txt or csv file to windows form c# 无法将图像文件上传到 Firebase 存储 - Unity C# - Unable to Upload Image file to Firebase Storage - Unity C# 文件不上传 Windows 表单 C# - File doesn't upload windows form C# C#Azure存储-如何将文件上传到已经存在的容器 - C# Azure Storage - How to Upload a File to an already Existing Container 如何使用 C# 将文件上传到 Azure Blob 存储? - How to upload file into Azure Blob Storage using C#? 如何在C#Web Api中流式传输文件以进行数据库存储 - How to stream file upload in C# Web Api for database storage 如何在RichTextBox Windows Form C#上显示文件上传或下载进度 - How to show file upload or download progress on richtextbox windows form c# c#.NET multipart / form-data上传文件 - c# .NET multipart/form-data Upload A File 如何使用WebRequest从ac#Windows表单将文件上传到node.js服务器(使用强大)? - How to upload a file to a node.js server (using formidable) from a c# windows form using webRequest? 如何使用c#windows form应用程序将excel文件上传到sql数据库表 - how to Upload a excel file to sql database table using c# windows form application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM