private void GetAllAudio(string imageName) { byte[] fileContents = { }; const long maxAllowedSize = 34008512; foreach (string key in keysList) { audio_ref = storage_ref.Child(key); audio_ref.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log("Downloading Failed"); Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! } else { fileContents = task.Result; float[] newAudioData = new float[fileContents.Length / 4]; System.Buffer.BlockCopy(fileContents, 0, audioData, 0, fileContents.Length); audioList.Add(newAudioData); } }); } }
public static async Task <byte[]> DownloadBytes(string URL) { if (string.IsNullOrEmpty(URL)) { throw new ArgumentException($"'{nameof(URL)}' cannot be null or empty.", nameof(URL)); } Debug.Log($"Downloading {URL}"); StorageReference reference = storage.RootReference.Child(URL); byte[] result = null; // Download to the local filesystem await reference.GetBytesAsync(1 * 1024 * 1024).ContinueWithOnMainThread(task => { if (task.IsFaulted || task.IsCanceled) { //Debug.LogException(task.Exception); Debug.Log("Error"); } else { byte[] output = task.Result; result = output; Debug.Log($"Finished downloading {URL}!"); } }); return(result); }
private IEnumerator DisplayScreenshotCoroutine() { // 다운할 파일의 경로지정 var storage = FirebaseStorage.DefaultInstance; // 파일이름 임의로 지정 StorageReference screenshotReference = storage.GetReferenceFromUrl(PATH).Child($"/screenshots/dog-2785077_640.jpg"); #region Print-On-Texture2D // Storage에서 이미지 다운받아 Texture에 출력하기 //GetBytesAsync(long.MaxValue); => 최대 사이즈 지정해준 것 var downloadTask = screenshotReference.GetBytesAsync(long.MaxValue); yield return(new WaitUntil(() => downloadTask.IsCompleted)); if (downloadTask.Exception != null) { Debug.LogError($"이미지 가져오기에 실패했습니다. {downloadTask.Exception}"); yield break; } else { // 다운 받은 이미지를 texture에 출력해준다! var texture = new Texture2D(2, 2); texture.LoadImage(downloadTask.Result); OnScreenshotDownloaded.Invoke(texture); } #endregion }
public static void LoadItemImage(Item item, GameObject slotSnap) { // Create a reference for the image StorageReference imageReference = FirebaseStorage.DefaultInstance.GetReference("images").Child("items").Child(item.itemId); // Load the image bytes from url const long maxAllowedSize = 1 * 1024 * 1024; imageReference.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log("Failed to load images: " + task.Exception.ToString()); ViewMessageOnScreen("Failed to load images: " + task.Exception.ToString()); } else { byte[] imageContents = task.Result; if (slotSnap) { Debug.Log("Retrieved image bytes ... "); Debug.Log(imageContents.Length); //slotTex = slotSnap.GetComponent<RawImage>().texture; snapBytes = imageContents; //slotTex = tex; snapshotsLoaded = true; } } }); }
private void DownloadPhotoGetBytesAsync(string Filename) { storage_ref.GetBytesAsync(10000000). ContinueWith((System.Threading.Tasks.Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); lastStatus = "ERROR: " + task.Exception.ToString(); } else { byte[] fileContents = task.Result; Debug.Log("fileContents.Length: " + fileContents.Length); Debug.Log("Got 1"); Debug.Log("Got 2"); Texture2D newTexture = new Texture2D(1, 1); Debug.Log("Got 3"); newTexture.LoadImage(fileContents); Debug.Log("Got 4"); photoRawImage.texture = newTexture; Debug.Log("Finished downloading! newTexture.graphicsFormat = " + newTexture.graphicsFormat); Debug.Log("newTexture.width = " + newTexture.width); lastStatus = "Downloaded photo!"; } }); }
public void testDownload() { downloading.text = "Downloading"; byte[] fileContents = { }; const long maxAllowedSize = 34008512; audio_ref.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log("Downloading Failed"); Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! } else { fileContents = task.Result; Debug.Log("Finished downloading!"); audioData = new float[fileContents.Length / 4]; Debug.Log("1"); System.Buffer.BlockCopy(fileContents, 0, audioData, 0, fileContents.Length); //audioSource.Play(); Debug.Log("2"); updating = true; Debug.Log("3"); downloading.text = "Download"; } }); /* * float[] floatFileContents = new float[fileContents.Length / 4]; * * System.Buffer.BlockCopy(fileContents, 0, floatFileContents, 0, fileContents.Length); * //audioSource.Play(); * * float[] audioSample = new float[audioSource.clip.samples]; * audioSource.Play(); * for (int i = 0; i < audioSample.Length; i ++) { * * audioSample[i] = floatFileContents[i]; * } */ //audioSource.Play(); //audioSource.Play(); //AudioClip downloadedAudio = AudioClip.Create("new", floatFileContents.Length, 4, 1, false); //audioSource.Play(); //downloadedAudio.SetData(floatFileContents, 0); //audioSource.clip = downloadedAudio; //audioSource.Play(); }
IEnumerator DownloadFromFirebaseStorage() { StorageReference reference = FirebaseStorage.DefaultInstance .GetReferenceFromUrl(firebaseStorageLocation); var task = reference.GetBytesAsync(1024 * 1024); yield return(new WaitUntil(() => task.IsCompleted)); if (task.IsFaulted) { DebugLog(task.Exception.ToString()); } else { fileContents = Encoding.UTF8.GetString(task.Result); DebugLog("Finished downloading..."); DebugLog("Contents=" + fileContents); } }
public void GetAudioAndPosition(string key, string imageName) { FirebaseDatabase.DefaultInstance .GetReference(imageName) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { error = "Error!"; } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; DataSnapshot c = snapshot.Child(key); double value0 = (double)c.Child("0").Value; double value1 = (double)c.Child("1").Value; double value2 = (double)c.Child("2").Value; position = new float[] { (float)value0, (float)value1, (float)value2 }; updatingPosition = true; } }); byte[] fileContents = { }; const long maxAllowedSize = 34008512; audio_ref = storage_ref.Child(key); audio_ref.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log("Downloading Failed"); Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! } else { fileContents = task.Result; audioData = new float[fileContents.Length / 4]; System.Buffer.BlockCopy(fileContents, 0, audioData, 0, fileContents.Length); updatingAudio = true; } }); }
IEnumerator DownloadFromFirebaseStorage() { StorageReference reference = FirebaseStorage.DefaultInstance .GetReferenceFromUrl(firebaseStorageLocation); var task = reference.GetBytesAsync(1024 * 1024); yield return(new WaitUntil(() => task.IsCompleted)); if (task.IsFaulted) { DebugLog(task.Exception.ToString()); } else { fileContents = Encoding.UTF8.GetString(task.Result); //DebugLog("Finished downloading..."); //DebugLog("Contents=" + fileContents); // Send quizz data to Data Controller EventManager.TriggerEvent(Constants.ON_REMOTE_DATA_RECEIVED, new BasicEvent(fileContents)); } }
public static IEnumerator LoadFromCloud(System.Action onComplete) { StorageReference targetStorage = GetTargetCloudStorage(); bool isCompleted = false; bool isSuccessfull = false; const long maxAllowedSize = 1024 * 1024; // Sama dengan 1 MB targetStorage.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) => { if (!task.IsFaulted) { string json = Encoding.Default.GetString(task.Result); Progress = JsonUtility.FromJson <UserProgressData>(json); isSuccessfull = true; } isCompleted = true; }); while (!isCompleted) { yield return(null); } // Jika sukses mendownload, maka simpan data hasil download if (isSuccessfull) { Save(); } else { // Jika tidak ada data di cloud, maka load data dari local LoadFromLocal(); } onComplete?.Invoke(); }
/// <summary> /// Downlaod file form current storage location /// </summary> /// <param name="targetPath">current file path</param> /// <returns>file binary file</returns> public async Task <DownloadedFile> DownloadFileFromStorage(string targetPath, FirebaseUser user) { isDonwloaded = true; DownloadedFile current = new DownloadedFile(); Storage_ref = Storage.GetReferenceFromUrl(targetPath); const long maxAllowedSize = 500 * 1024 * 1024; //max donwload file 500MB await Storage_ref.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! isDonwloaded = false; } else { //save file to byte array current.SetData(task.Result); Debug.Log("Finished downloading!"); } }); await Storage_ref.GetMetadataAsync().ContinueWith((Task <StorageMetadata> task) => { if (!task.IsFaulted && !task.IsCanceled) { StorageMetadata meta = task.Result; current.SetFileType(meta.ContentType); } }); isDonwloaded = false; return(current); }
public void DownloadFile(string filename) { Debug.Log("Downloading: " + filename); StorageReference path_reference = storage.GetReference(filename); const long maxAllowedSize = 10 * 1024 * 1024; path_reference.GetBytesAsync(maxAllowedSize).ContinueWith((Task <byte[]> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); Debug.Log("No case with this name"); } else { Debug.Log("Finished downloading"); Stream stream = new MemoryStream(task.Result); BinaryFormatter bf = new BinaryFormatter(); Case downloadedCase = (Case)bf.Deserialize(stream); UIManager.Instance.activeCase = downloadedCase; downloaded = true; } }); }