0

I am developing an app in unity that uses both firebase Auth and a real-time database and firebase storage. On the signup page, I could sign up and upload data to the real-time database using RestApi successfully. I used "RestClient" for this. But when I tried to upload the image to the firebase storage it failed. And return an error. below is the code can anyone please tell me what is wrong with this and how to fix it?

private void SignUpUser(string email, string username, string password, string age_, string mobile_, string instagram_handle_, string City_Of_Residence_, string nationality_)
    {
        string userData = "{\"email\":\"" + email + "\",\"password\":\"" + password + "\",\"returnSecureToken\":true}";
        RestClient.Post<SignResponse>("https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=" + AuthKey, userData).Then(
            response =>
            {
                idToken = response.idToken;
                localId = response.localId;
                playerName = username;
                age = age_;
                mobile = mobile_;
                instagram_handle = instagram_handle_;
                City_Of_Residence = City_Of_Residence_;
                nationality = nationality_;
                PostToDatabase(true);
                
                

                RestClient.Post<SignResponse>("https://firebasestorage.googleapis.com/v0/b/1:1099162121592:web:4838414d2537d05540414x/o/%2F"+idToken+"?alt=media",file2upload.sprite).Then(
                     response =>
                    {
                        
                    }).Catch(error=>
                    {
                        Debug.Log("Image upload error: "+ error);
                    });
                
                print("Data uploaded");
                
            }).Catch(error =>
        {
            Debug.Log(error);
        });
    } 
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Savad
  • 1,240
  • 3
  • 21
  • 50

1 Answers1

0

What is your build target? If mobile, use the provided Firebase SDK for Unity. If your target platform is standalone, you can't use the Firebase SDK for Unity.

Unfortunately, Firebase does not provide a REST API for Firebase Storage, but they do for Google Cloud Storage (Firebase storage being based on GCS), take a look here: storage JSON API doc

From here, you need to authenticate through the Google OAuth2 pipeline (not the firebase one) to get an auth token that you'll include in all your requests header.

See this topic for more details.

Sov3rain
  • 21
  • 3
  • i am developing WebGL app – Savad Aug 10 '22 at 14:07
  • 1
    Well, it means that you can't use the Firebase SDK for Unity. You need to either authenticate your users with Google OAuth2 protocol instead of Firebase Authentication or find a way to exchange your Firebase auth token for an OAuth2 Token. – Sov3rain Aug 10 '22 at 15:28