Hi Is there any way to open a file stream from a file stored in streaming assets? Currently thought i may have a way of doing it but whenever i then try and look into the database for information it crashes and throws memory access errors. I have a database in the streaming assets that is able to run online but i need to be able to access this information. Other thinking is can i download and cache this locally and then file stream from the local file in Temp or somewhere else (I have seen a few ways to upload an image from your desktop and wondering if this would work with a file stream) Thanks
Hi So i have got a unity web request accessing the file and giving me back the byte[] data then using this to create a memory stream which i was hoping would allow me to access the data. however although the memory stream is created and contains the correct number of bytes, I am unable to then access the stream afterwards. Any idea what could be causing this?
Code (CSharp): MemoryStream theMemStream; // Start is called before the first frame update IEnumerator Start() { yield return StartCoroutine(Stream()); Debug.Log(theMemStream.Length); LiteDatabase liteDatabase = new LiteDatabase(theMemStream); IEnumerable<string> x = liteDatabase.GetCollectionNames(); foreach (string variable in x) { Debug.Log(variable); } Debug.Log("Hello"); //Debug.Log(liteDatabase.GetCollection<MyData>().Count()); List<MyData> data = liteDatabase.GetAllCollectionData<MyData>(); Debug.Log(data.Count); foreach (MyData myData in data) { Debug.Log(myData.Message); message = myData.Message; } Debug.Log("Do we even get here"); } IEnumerator Stream() { string url = Path.Combine(Application.streamingAssetsPath, "Blank.db"); Debug.Log(url); //UnityWebRequest request = new UnityWebRequest(); byte[] dbData; //Check if we should use UnityWebRequest or File.ReadAllBytes if (url.Contains("://") || url.Contains(":///")) { UnityWebRequest www = UnityWebRequest.Get(url); yield return www.SendWebRequest(); dbData = www.downloadHandler.data; } else { dbData = File.ReadAllBytes(url); } // yield return request.SendWebRequest(); Debug.Log(dbData.Length); // Debug.Log("Downloading File"); // DownloadFile(imgData, imgData.Length, "blank.db"); theMemStream = new MemoryStream(); theMemStream.Write(dbData, 0, dbData.Length); Debug.Log($"Memory stream is {theMemStream.Length} bytes"); } This is what i have so far. Error being generated after the build it as followed "exception thrown: RuntimeError: index out of bounds,@blob:null/9fb8a57f-4ab1-44f8-8d21-4764a76e9f76 line 275 > WebAssembly.instantiate:wasm-function[14213]:0x5940aa" The get collections names outputs fine, but then the getting data within them causing this error
It sounds like it crashes when you iterate on the list returned by GetAllCollectionData() I suggest you test it on a different il2cpp-platform (Mobile or Standalone, just make sure scripting backend is il2cpp). Make sure to host the file with a simple http server, then download it using UnityWebRequest like you would on WebGL.