Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Unity到Firebase的简单图像上载不起作用_C#_Unity3d_Firebase Storage - Fatal编程技术网

C# 从Unity到Firebase的简单图像上载不起作用

C# 从Unity到Firebase的简单图像上载不起作用,c#,unity3d,firebase-storage,C#,Unity3d,Firebase Storage,我正在开发一款IOS应用程序,我在C#中使用Unity创建了该应用程序(Unity 2018.2.5f1)。现在,我正尝试将一个图像上传到Firebase存储,以熟悉它。不幸的是,这不起作用 我假设本地文件的路径有问题。运行应用程序时,我在XCode中遇到以下错误 Firebase.Storage.Storage.StorageException:所需引用处没有对象 文件swift.jpg肯定存在于iPhone上 非常欢迎你的帮助 using UnityEngine; using Firebas

我正在开发一款IOS应用程序,我在C#中使用Unity创建了该应用程序(Unity 2018.2.5f1)。现在,我正尝试将一个图像上传到Firebase存储,以熟悉它。不幸的是,这不起作用

我假设本地文件的路径有问题。运行应用程序时,我在XCode中遇到以下错误

Firebase.Storage.Storage.StorageException:所需引用处没有对象

文件swift.jpg肯定存在于iPhone上

非常欢迎你的帮助

using UnityEngine;
using Firebase.Storage;
using System.Threading.Tasks;

public class Upload : MonoBehaviour {

    FirebaseStorage storage;
    StorageReference storage_ref;

    // Use this for initialization
    void Start () {
        storage = FirebaseStorage.DefaultInstance;
        storage_ref = storage.GetReferenceFromUrl("gs://[My Storage URL]");

        // File located on disk
        string local_file = Application.persistentDataPath + "/" + "swift.jpg";

        // Create a reference to the file you want to upload
        StorageReference image_ref = storage_ref.Child("images/swift.jpeg");

        // Upload the file to the path
        image_ref.PutFileAsync(local_file)
          .ContinueWith((Task<StorageMetadata> task) => {
              if (task.IsFaulted || task.IsCanceled) {
                  Debug.Log(task.Exception.ToString());
                  // Uh-oh, an error occurred!
              }
              else {
                  // Metadata contains file metadata such as size, content-type, and download URL.
                  // StorageMetadata metadata = task.Result;
                  // string download_url = metadata.DownloadUrl.ToString();
                  // Debug.Log("Finished uploading...");
                  // Debug.Log("download url = " + download_url);
              }
          });
    }

}
使用UnityEngine;
使用Firebase。储存;
使用System.Threading.Tasks;
公共类上传:MonoBehavior{
火基储存;
存储参考存储;
//用于初始化
无效开始(){
存储=FirebaseStorage.DefaultInstance;
storage\u ref=storage.GetReferenceFromUrl(“gs://[My storage URL]”);
//文件位于磁盘上
字符串local_file=Application.persistentDataPath+“/”+“swift.jpg”;
//创建对要上载的文件的引用
StorageReference image_ref=storage_ref.Child(“images/swift.jpeg”);
//将文件上载到路径
image\u ref.PutFileAsync(本地\u文件)
.ContinueWith((任务)=>{
if(task.IsFaulted | | task.IsCanceled){
Debug.Log(task.Exception.ToString());
//哦,发生了一个错误!
}
否则{
//元数据包含文件元数据,如大小、内容类型和下载URL。
//StorageMetadata=task.Result;
//string download_url=metadata.DownloadUrl.ToString();
//Log(“已完成上载…”);
//Log(“下载url=“+下载url”);
}
});
}
}
试试看


希望其中一个能起作用

哪一行代码导致错误?在XCode中调试。。。(Filename:/Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line:43)2019-01-06 21:59:55.922265+0100 arnav[6835:1687542]cfurlResourceisRechable失败,因为传递的URL没有方案2019-01-06 21:59:55.979115+0100 arnav[6835:1687542][MC]systemgroup.com.apple.configurationprofiles路径的系统组容器为/private/var/containers/Shared/systemgroup/systemgroup.com.apple.configurationprofiles 2019-01-06 21:59:55.979858+0100 arnav[6835:1687542][MC]从公共有效用户设置读取。上传被取消…”文件://“在iOS上为我修复了出现问题的地方。在编辑器中运行时未发生错误。添加协议似乎在编辑器中工作,也可以构建到iOS。对我来说,它是“file://”。谢谢
string local_file = "file:///" + Application.persistentDataPath + "/" + "swift.jpg";
string local_file = "file://" + Application.persistentDataPath + "/" + "swift.jpg";
string local_file = "file:\\" + Application.persistentDataPath + "/" + "swift.jpg";