【问题标题】:Google Firebase and Unity (C#): Unable to download png from bucketGoogle Firebase 和 Unity (C#):无法从存储桶下载 png
【发布时间】:2019-08-12 11:22:48
【问题描述】:

规格

Unity editor version:       2018.2.8f1
Firebase Unity SDK version: 5.5.0
Additional SDKs:            SimpleFirebaseUnity
Developing on:              Mac
Export Platform:            Android

问题

我在设置系统以从存储中下载图片时遇到问题。我不是数据库方面的专家,但我想尝试一下,只是为了了解它是如何完成的。 我发现 Firebase 对于将元数据存储在实时数据库中非常有用,而且即使对于像我这样的入门级程序员来说也很容易使用。

问题是我正在尝试从存储中的文件夹下载.png 文件,但我无法找到该文件是实际下载的还是在此过程中丢失了。我在控制台中没有收到任何错误,但是当我打开文件所在的文件夹时,它是空的。

代码

private SimpleFirebaseUnity.Firebase firebaseDatabase;
private FirebaseQueue firebaseQueue;
private FirebaseStorage firebaseStorage;
private StorageReference m_storage_ref;

// Setup refernece to database and storage
void SetupReferences()
{
    // Get a reference to the database service, using SimpleFirebase plugin
    firebaseDatabase = SimpleFirebaseUnity.Firebase.CreateNew(FIREBASE_LINK, FIREBASE_SECRET);

    // Get a reference to the storage service, using the default Firebase App
    firebaseStorage = FirebaseStorage.DefaultInstance;

    // Create a storage reference from our storage service
    m_storage_ref = firebaseStorage.GetReferenceFromUrl(STORAGE_LINK);

    // Create a queue, using SimpleFirebase
    firebaseQueue = new FirebaseQueue(true, 3, 1f);
}

// ...

IEnumerator DownloadImage(string address, string fileName)
{
    var local_path = Application.persistentDataPath + THUMBNAILS_PATH;
    var content_ref = m_storage_ref.Child(THUMBNAILS_PATH + fileName + ".png");

    content_ref.GetFileAsync(local_path).ContinueWith(task => {
        if (!task.IsFaulted && !task.IsCanceled)
        {
            Debug.Log("File downloaded.");
        }
    });

    yield return null;
}

【问题讨论】:

    标签: c# firebase unity3d firebase-realtime-database download


    【解决方案1】:

    这对您不起作用的原因有很多,包括:

    • 安全规则设置不正确
    • 文件路径不正确
    • 您在错误的平台上对其进行测试(Firebase 在编辑器中无法正常运行)
    • 您的设备阻止了连接
    • 等等……

    为了获得错误消息,您需要记录它们:

    IEnumerator DownloadImage(string address, string fileName)
    {
        var local_path = Application.persistentDataPath + THUMBNAILS_PATH;
        var content_ref = m_storage_ref.Child(THUMBNAILS_PATH + fileName + ".png");
    
        content_ref.GetFileAsync(local_path).ContinueWith(task => {
            if (!task.IsFaulted && !task.IsCanceled)
            {
                Debug.Log("File downloaded.");
            }
            else
            {
                Debug.Log(task.Exception.ToString());
            }
        });
    
        yield return null;
    }
    

    请记住,在编辑器中测试它可能不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-25
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      相关资源
      最近更新 更多