简体   繁体   中英

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

I Tried the Following Function to upload an image to Firebase Storage

 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." } }

You have to edit your Bucket variable. Instead of using gs://xxxxx.appspot.com/ it should be only xxxxx.appspot.com

here I have a code that can help you load an image in base64 format in realtime database. I'll give you the link see you soon.

How to upload a pdf file to google storage using visual C #?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM