[英]How to upload files to firebase storage using rest api in Unity C#
我正在统一开发一个应用程序,它同时使用 firebase Auth 和实时数据库以及 firebase 存储。 在注册页面上,我可以成功注册并使用 RestApi 将数据上传到实时数据库。 我为此使用了“RestClient”。 但是当我尝试将图像上传到 firebase 存储时,它失败了。 并返回错误。 下面是代码,谁能告诉我这有什么问题以及如何解决?
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);
});
}
你的构建目标是什么? 如果是移动设备,请使用提供的Firebase SDK for Unity 。 如果您的目标平台是独立的,则不能将 Firebase SDK 用于 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
从这里开始,您需要通过 Google OAuth2 管道(不是 firebase 管道)进行身份验证,以获得将包含在所有请求 header 中的身份验证令牌。
有关更多详细信息,请参阅此主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.