【发布时间】:2021-09-15 11:23:54
【问题描述】:
我正在尝试使用 Unity 2020.3.6f1 将图像文件上传到“Firebase 存储”。 这是我遇到的错误。
Assets\script\FileManager.cs(72,50):错误 CS1061:“StorageMetadata”不包含“profile_ref”的定义,并且没有可访问的扩展方法“profile_ref”接受“StorageMetadata”类型的第一个参数找到(您是否缺少 using 指令或程序集引用?)
我使用"NativeGallery". Unity Plugin 从图库中检索本地图像文件。
有人知道为什么会出现这个错误吗?
这是我的代码:
public Image profileImage;
public void BringImage()
{
PickImage(1024);
}
private void PickImage(int maxSize)
{
NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
{
Debug.Log("Image path: " + path);
if (path != null)
{
// Create Texture from selected image
Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
if (texture == null)
{
Debug.Log("Couldn't load texture from " + path);
return;
}
Rect rect = new Rect(0, 0, texture.width, texture.height);
profileImage.sprite = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f));
UploadImage(path);
}
});
Debug.Log("Permission result: " + permission);
}
public void UploadImage(string path)
{
FirebaseStorage storage = FirebaseStorage.DefaultInstance;
StorageReference storageRef = storage.GetReferenceFromUrl("gs://modoodle-backend-91a60.appspot.com/");
Firebase.Storage.StorageReference profile_ref = storageRef.Child(IDRegisterManager.email + "/profileImages/profileImage.jpg");
// Upload the file to the path IDRegisterManager.email + "/profileImage"
profile_ref.PutFileAsync("file://" + path)
.ContinueWith((Task<StorageMetadata> task) =>
{
if (task.IsFaulted || task.IsCanceled)
{
Debug.Log(task.Exception.ToString());
}
else
{
// Metadata contains file metadata such as size, content-type, and download URL.
Firebase.Storage.StorageMetadata metadata = task.Result;
string download_url = metadata.profile_ref.ToString();
Debug.Log("Finished uploading...");
Debug.Log("download url = " + download_url);
}
});
}
}
【问题讨论】:
标签: c# firebase unity3d firebase-storage