public void testFirebase(string key) { //Using the Buffer solution audio_ref = storage_ref.Child(key); uploading.text = "Uploading"; float[] samples = new float[audioClipFromDB.samples]; audioClipFromDB.GetData(samples, 0); byte[] byteSamples = new byte[audioClipFromDB.samples * 4]; System.Buffer.BlockCopy(samples, 0, byteSamples, 0, byteSamples.Length); audio_ref.PutBytesAsync(byteSamples) .ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { //audioSource.Play(); Debug.Log("Uploading Failed"); Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! } else { // Metadata contains file metadata such as size, content-type, and download URL. Debug.Log("Upload Success"); //audioSource.Play(); Firebase.Storage.StorageMetadata metadata = task.Result; //audioSource.Play(); string download_url = metadata.Reference.GetDownloadUrlAsync().ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); uploading.text = "Upload"; } }); //audioSource.Play(); }
// Start is called before the first frame update void Start() { var storage = FirebaseStorage.DefaultInstance; // 테스트할 때마다 경로 바꿔서 테스트 가능 var screenshotReference = storage.GetReferenceFromUrl(PATH).Child($"/screenshots/city-4298285_640.jpg"); #region Set-Metadata var metadataChange = new MetadataChange() { CustomMetadata = new Dictionary <string, string>() { //{ "Position", Camera.main.transform.position.ToString()}, { "Location", "카페" } } }; #endregion screenshotReference.UpdateMetadataAsync(metadataChange).ContinueWith(task => { if (!task.IsFaulted && !task.IsCanceled) { // access the updated meta data Firebase.Storage.StorageMetadata meta = task.Result; } }); }
// mp4 movie upload... 테스트 안 해봤음. IEnumerator UploadProcessByteBufferMP4Format() { yield return(new WaitForEndOfFrame()); Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; // Create a storage reference from our storage service Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://fir-authtest22.appspot.com"); string local_file = ""; if (Application.platform == RuntimePlatform.Android) { local_file = Application.persistentDataPath + "/" + fileName; } else { local_file = "C:/Users/Gana/Downloads/Test_imgs/" + fileName; } Firebase.Storage.StorageReference rivers_ref = storage_ref.Child("stuff/" + fileName); WWW www = new WWW("file:///" + local_file); while (!www.isDone) { yield return(null); } Texture2D tmpTexture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.RGB24, false); tmpTexture.SetPixels(www.texture.GetPixels()); tmpTexture.Apply(); byte[] bytes = tmpTexture.EncodeToPNG(); var TmpTask = rivers_ref.PutBytesAsync(bytes, null, new Firebase.Storage.StorageProgress <Firebase.Storage.UploadState>(state => { Debug.Log(string.Format("Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount)); PercentView(state.BytesTransferred, state.TotalByteCount); }), System.Threading.CancellationToken.None, null).ContinueWith(task => { Debug.Log(string.Format("OnClickUpload::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted)); 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. Firebase.Storage.StorageMetadata metadata = task.Result; Debug.Log("Finished uploading..."); //foreach (var entry in metadata.DownloadUrls) // Debug.Log("download url = " + entry); } }); yield return(new WaitUntil(() => TmpTask.IsCompleted)); PrintState("uploading complete.."); }
private void PublishImageToStorage(string localFile, string key) { // Create a reference to the file you want to upload StorageReference imageReference = storageFolderReference.Child($"{key}.jpg"); // Upload the file to the itemPath imageReference.PutFileAsync(localFile) .ContinueWith((task) => { // error uploading if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); } // uploaded successfuly else { // Metadata contains file metadata such as size, content-type, and download URL. Firebase.Storage.StorageMetadata metadata = task.Result; imageReference.GetMetadataAsync().ContinueWith((task2) => { string downloadUrl = task2.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + downloadUrl); }); } }); }
public void upload(byte[] custom_bytes, string fbPath, Action <string> cb) { authDoneCB.add(() => { StorageReference rivers_ref = getByPath(fbPath); // Upload the file to the path "images/rivers.jpg" rivers_ref.PutBytesAsync(custom_bytes) .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. Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.Path; UnityMainThreadDispatcher.uniRxRun(() => { cb(metadata.Path); Debug.Log("Finished uploading..."); }); } }); }); }
protected void UploadOriginalFileToStorage(string fileName, string filePath, string uploadStoragePath) { byte[] bytes = File.ReadAllBytes(filePath); string path = uploadStoragePath; // Create a reference with an initial file path and name Firebase.Storage.StorageReference path_reference = storage.GetReference(path); // Upload the file to the path "images/rivers.jpg" path_reference.PutBytesAsync(bytes) .ContinueWith((Task <Firebase.Storage.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. Firebase.Storage.StorageMetadata metadata = task.Result; //string download_url = metadata.DownloadUrl.ToString(); Debug.Log(fileName + " Finished uploading..."); progress += 1; // Fetch the download URL path_reference.GetDownloadUrlAsync().ContinueWith((Task <Uri> getURLtask) => { if (!getURLtask.IsFaulted && !getURLtask.IsCanceled) { AssetsExporter.modelsDict[fileName][AssetsExporter.modelDBURLKey] = getURLtask.Result; } }); } }); }
public void BuildTarget() { if (udt_FrameQuality == ImageTargetBuilder.FrameQuality.FRAME_QUALITY_HIGH) { udt_targetBuildingBehavior.BuildNewTarget(targetCounter.ToString(), targetBehavior.GetSize().x); Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://ar-demo-1f5c9.appspot.com"); Firebase.Storage.StorageReference file_ref = storage_ref.Child("images/" + FileControl.FilePath); file_ref.PutFileAsync("./Assets/Resources/" + FileControl.FilePath + ".txt").ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log("STILL HERE"); Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! } else { // Metadata contains file metadata such as size, content-type, and download URL. Firebase.Storage.StorageMetadata metadata = task.Result; //string download_url = metadata.DownloadUrl.ToString(); //Debug.Log("Finished uploading..."); //Debug.Log("download url = " + download_url); } }); } }
public void SubmitData() { DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference; reference.Child(emailText).Child(LCGoogleLoginBridge.GSIEmail()) .SetRawJsonValueAsync(JsonConvert.SerializeObject(_AppRequest)); reference.Child(messageText.text).Child(_AppRequest.message) .SetRawJsonValueAsync(JsonConvert.SerializeObject(_AppRequest)); reference.Child(locationText.text).Child(_AppRequest.location) .SetRawJsonValueAsync(JsonConvert.SerializeObject(_AppRequest)); StorageReference storage = FirebaseStorage.DefaultInstance.RootReference; Firebase.Storage.StorageReference img_ref = storage.Child("UserImages/user.jpg"); ImageGet.instance.imgTex.GetRawTextureData(); img_ref.PutBytesAsync(ImageGet.instance.imgTex.GetRawTextureData()) .ContinueWith((System.Threading.Tasks.Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); } else { Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.DownloadUrl.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); } }); }
private void SendAudio(string key, float[] audio) { //Using the Buffer solution audio_ref = storage_ref.Child(key); byte[] byteSamples = new byte[audioClipFromDB.samples * 4]; System.Buffer.BlockCopy(audio, 0, byteSamples, 0, byteSamples.Length); audio_ref.PutBytesAsync(byteSamples) .ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { //audioSource.Play(); Debug.Log("Uploading Failed"); Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! } else { Debug.Log("Upload Success"); Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.Reference.GetDownloadUrlAsync().ToString(); } }); }
public void UploadProfilePic() { FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storage_ref = GetStorageReference(); var profilePicReference = storage_ref.Child("images/" + auth.CurrentUser.Email); Byte[] profile = FacebookManager.Instance.ProfileTexture.EncodeToPNG(); profilePicReference.PutBytesAsync(profile) .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. Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = storage_ref.GetDownloadUrlAsync().ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); } }); }
void OnDestroy() { // Write and save game data to .json file string saveText = JsonUtility.ToJson(listw); Debug.Log("readAler: " + saveText); string datetime = DateTime.Now.ToString("yyyyMMddHHmmss"); if (!Directory.Exists(out_folder)) { Directory.CreateDirectory(out_folder); } if (!Directory.Exists(out_folder + gameObject.name + "/" + "pickup/")) { Directory.CreateDirectory(out_folder + gameObject.name + "/" + "pickup/"); } string filename = "pickup_" + datetime + ".json"; string local_filepath = out_folder + gameObject.name + "/" + "pickup/" + filename; File.WriteAllText(local_filepath, saveText); // TODO @Matthew: This takes 2 arguments, the filepath and the json saveText var // Get a reference to Firebase cloud storage service Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; // Create storage reference from our storage service bucket Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://unityoptics-eafc0.appspot.com"); // Create a reference to newly created .json file Firebase.Storage.StorageReference game_data_ref = storage_ref.Child(filename); // Create reference to 'gameData/filename' Firebase.Storage.StorageReference game_data_json_ref = storage_ref.Child("gameData/" + gameObject.name + "/" + "pickup/" + filename); // Upload Files to Cloud FireStore game_data_json_ref.PutFileAsync(local_filepath) .ContinueWith((System.Threading.Tasks.Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); // Error Occured } else { //Metadata contains file metadata such as size, content-type, and download URL. Firebase.Storage.StorageMetadata metadata = task.Result; // string download_url = metadata.DownloadUrl.ToString(); Debug.Log("Finished uploading..."); // Debug.Log("download url = " + download_url); } }); }
protected void GrabPixelsOnPostRender(string fileName) { //Create a new texture with the width and height of the screen Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); //Read the pixels in the Rect starting at 0,0 and ending at the screen's width and height texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false); texture.Apply(); byte[] bytes = texture.EncodeToPNG(); string path = AssetsExporter.imagesStorageURL + fileName + ".png"; // Create a reference with an initial file path and name Firebase.Storage.StorageReference path_reference = storage.GetReference(path); // Upload the file to the path "images/rivers.jpg" path_reference.PutBytesAsync(bytes) .ContinueWith((Task <Firebase.Storage.StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); Debug.Log("task failed: " + path + " " + fileName); // Uh-oh, an error occurred! } if (task.IsCanceled) { Debug.Log("task was canceled"); } else { // Metadata contains file metadata such as size, content-type, and download URL. Firebase.Storage.StorageMetadata metadata = task.Result; //string download_url = metadata.DownloadUrl.ToString(); Debug.Log(fileName + " Finished uploading..."); progress += 1; // Fetch the download URL path_reference.GetDownloadUrlAsync().ContinueWith((Task <Uri> getURLtask) => { if (!getURLtask.IsFaulted && !getURLtask.IsCanceled) { AssetsExporter.modelsDict[fileName][AssetsExporter.modelDBImageKey][AssetsExporter.modelDBImageURLKey] = getURLtask.Result; } }); } }); }
public void uploadImageToFirebase() { string local_file = Application.persistentDataPath + "/Snapshots/screenshot.png"; screenshot_ref.PutFileAsync(local_file).ContinueWith(task => { if (task.IsFaulted || task.IsCanceled) { Debug.Log("isFaulted or IsCancelled: " + task.Exception.ToString()); } else { Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.DownloadUrl.ToString(); Debug.Log("Finished Uploading..."); Debug.Log("Download URL = " + download_url); } }); }
public static IStorageMetadata ToAbstract(this NativeStorageMetadata @this) { return(new StorageMetadata( bucket: @this.Bucket, generation: @this.Generation, metaGeneration: @this.Metageneration, name: @this.Name, path: @this.Path, size: @this.Size, cacheControl: @this.CacheControl, contentDisposition: @this.ContentDisposition, contentEncoding: @this.ContentEncoding, contentLanguage: @this.ContentLanguage, contentType: @this.ContentType, customMetadata: @this.CustomMetadata?.ToDictionary(), md5Hash: @this.Md5Hash, storageReference: @this.StorageReference?.ToAbstract(), creationTime: @this.TimeCreated.ToDateTimeOffset(), updatedTime: @this.Updated.ToDateTimeOffset())); }
public static IStorageMetadata ToAbstract(this NativeStorageMetadata @this) { return(new StorageMetadata( bucket: @this.Bucket, generation: Long.ParseLong(@this.Generation), metaGeneration: Long.ParseLong(@this.MetadataGeneration), name: @this.Name, path: @this.Path, size: @this.SizeBytes, cacheControl: @this.CacheControl, contentDisposition: @this.ContentDisposition, contentEncoding: @this.ContentEncoding, contentLanguage: @this.ContentLanguage, contentType: @this.ContentType, customMetadata: @this.CustomMetadataKeys?.Select(x => (x, @this.GetCustomMetadata(x))).ToDictionary(x => x.Item1, x => x.Item2), md5Hash: @this.Md5Hash, storageReference: @this.Reference?.ToAbstract(), creationTime: DateTimeOffset.FromUnixTimeMilliseconds(@this.CreationTimeMillis), updatedTime: DateTimeOffset.FromUnixTimeMilliseconds(@this.UpdatedTimeMillis))); }
private void CreatePlayerRecordFile() { string fileName = this.GenerateRecordFileName(); while (File.Exists(fileName)) { this.round++; fileName = this.GenerateRecordFileName(); } string json = JsonUtility.ToJson(this); Directory.CreateDirectory(@"Records/" + this.bossName); System.IO.File.WriteAllText(fileName, json); FirebaseApp app = FirebaseApp.Create(); FirebaseStorage storage = FirebaseStorage.GetInstance(CLOUD_STORAGE_URL); this.storage_ref = storage.GetReferenceFromUrl(CLOUD_STORAGE_URL); StorageReference record_ref = this.storage_ref.Child(fileName); record_ref.PutBytesAsync(Encoding.UTF8.GetBytes(json)) .ContinueWith(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. Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.DownloadUrl.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); this.isFileUploaded = true; } }); alertText.gameObject.SetActive(true); }
protected void UploadAssetBundleToStorage(string fileName, string filePath, string uploadStoragePath) { if (!File.Exists(filePath)) { status.SetActive(true); status.GetComponent <Text>().text = "Missing Asset Bundles!"; return; } byte[] bytes = File.ReadAllBytes(filePath); string path = uploadStoragePath; // Create a reference with an initial file path and name Firebase.Storage.StorageReference path_reference = storage.GetReference(path); // Upload the file to the path "images/rivers.jpg" path_reference.PutBytesAsync(bytes) .ContinueWith((Task <Firebase.Storage.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. Firebase.Storage.StorageMetadata metadata = task.Result; //string download_url = metadata.DownloadUrl.ToString(); Debug.Log(fileName + " Finished uploading..."); progress += 1; //Debug.Log("download url = " + download_url); path_reference.GetDownloadUrlAsync().ContinueWith((Task <Uri> getURLtask) => { if (!getURLtask.IsFaulted && !getURLtask.IsCanceled) { AssetsExporter.modelsDict[fileName][AssetsExporter.modelDBBundleURLKey] = getURLtask.Result; Debug.Log(getURLtask.Result); } }); } }); }
public void OnButtonPress() { foreach (string file_name in System.IO.Directory.GetFiles("Assets/AssetBundles")) { var file_ref = storage_ref.Child(file_name); file_ref.PutFileAsync(file_name).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; var download_result = storage_ref.GetDownloadUrlAsync(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_result.Result); } }); } }
/* * Debug function to ensure firebase storage is working correctly * */ public async void writeMap(byte[] data) { string path = app_folder + "/" + curUser.UserId + "/" + file_name; // Create a reference to 'app_height_maps/{userID}/"mobile_height_map.raw" Firebase.Storage.StorageReference abs_path = storage_ref.Child(path); await abs_path.PutBytesAsync(data).ContinueWith((Task <Firebase.Storage.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. Firebase.Storage.StorageMetadata metadata = task.Result; Debug.Log("Finished uploading..."); } }); }
//================================================= METADATA ==================================================// // Storage 상의 메타데이터 추가 및 교체.. public void MetadataChange() { Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; // Create a storage reference from our storage service Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://fir-authtest22.appspot.com"); // Create a reference to the file you want to upload Firebase.Storage.StorageReference rivers_ref = storage_ref.Child("Test1/test_arrow.png"); var new_metadata = new Firebase.Storage.MetadataChange(); //new_metadata.CacheControl = "public,max-age=300"; new_metadata.ContentType = "image/png"; // 아래처럼 Dictionary 활용하여서 추가할 수 있음.. // Issue 사항은 추가되면 수정은 가능하지만 삭제가 불가능한 것 같음.. /* * var new_metadata = new Firebase.Storage.MetadataChange * { * CustomMetadata = new Dictionary<string, string> * { * {"story", "story for test" }, * {"tag", "hmm...." }, * } * }; */ // Update metadata properties Task tmpTask = rivers_ref.UpdateMetadataAsync(new_metadata).ContinueWith(task => { if (!task.IsFaulted && !task.IsCanceled) { // access the updated meta data Firebase.Storage.StorageMetadata meta = task.Result; Debug.Log("change.."); } }); //yield return new WaitUntil(() => tmpTask.IsCompleted); // do someting... }
void UploadImageUrls() { string local_file = Application.persistentDataPath + "/cloudModels.json"; string sessionReference = CreateImageSession(); Firebase.Storage.StorageReference session_ref = user_ref.Child(sessionReference + "/Url.txt"); session_ref.PutFileAsync(local_file) .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.DownloadUrl.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); } }); }
void UploadImage() { Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; // Create a root reference Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl(firebaseStorageBucket); // File located on disk string local_file = localFilePath; // Create a reference to the file you want to upload Firebase.Storage.StorageReference image_ref = storage_ref.Child(remoteFilePath); // Upload the file to the path "images/rivers.jpg" 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. Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.DownloadUrl.ToString(); //fix the encoding problem string tempStr = remoteFilePath; downloadURL = download_url.Replace(tempStr, remoteFilePath.Replace("/", "%2F")); Debug.Log("Finished uploading"); //Debug.Log("download url = " + download_url); } }); }
public void saveRemember(Remember remember) { //Save Data Remember Dictionary <string, System.Object> entry = remember.ToDictionary(); string rememberCode = dataReference.Push().Key; remember.SetCode(rememberCode); dataReference.Child(rememberCode).SetValueAsync(entry).ContinueWith((task) => { if (task.IsCompleted) { Debug.Log("Data saved successfully!"); } else { }; });; //Save Media Data Remember GameObject mainCameraUI = GameObject.Find(Util.ARCamera); GameObject buttonLoading = mainCameraUI.GetComponent <UIController>().buttonLoading; mainCameraUI.GetComponent <UIController>().buttonCancelMedia.SetActive(false); mainCameraUI.GetComponent <UIController>().buttonSaveMedia.SetActive(false); buttonLoading.SetActive(true); // Create a reference to the file you want to upload Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl(FirebaseUtil.ROOTNODE_STORAGE); Firebase.Storage.StorageReference rivers_ref = storage_ref.Child(remember.GetCode() + ".jpeg"); rivers_ref.PutBytesAsync(remember.GetMedia(), null, new Firebase.Storage.StorageProgress <Firebase.Storage.UploadState>(state => { Debug.Log(string.Format("Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount)); decimal bytesTrasferred = System.Convert.ToDecimal(state.BytesTransferred); decimal totalByteCount = System.Convert.ToDecimal(state.TotalByteCount); decimal progress = ((bytesTrasferred / totalByteCount) * 100); decimal progressLoadingUI = (progress / 100); buttonLoading.GetComponent <LoadingController>().progressFillImage(progressLoadingUI); }), System.Threading.CancellationToken.None, null).ContinueWith(task => { Debug.Log(string.Format("OnClickUpload::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted)); 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. Firebase.Storage.StorageMetadata metadata = task.Result; GameObject buttonTimer = mainCameraUI.GetComponent <UIController>().buttonTimer; buttonTimer.gameObject.SetActive(true); if (remember.GetTypeMedia().Equals("Image")) { GameObject rememberGO = Instantiate(Resources.Load <GameObject>("Prefabs/Remember/RememberPhoto")); rememberGO.GetComponent <RememberPhotoController>().AddRemember(remember); rememberGO.GetComponent <RememberPhotoController>().UpdateTexture(); } else { GameObject rememberGO = Instantiate(Resources.Load <GameObject>("Prefabs/Remember/RememberVideo")); rememberGO.GetComponent <RememberVideoController>().AddRemember(remember); rememberGO.GetComponent <RememberVideoController>().UpdateTexture(); } Debug.Log("Finished uploading..."); Destroy(this.gameObject); } }); }
// 로컬 방식 업로드 부분... 로컬 방식이기 때문에 모든 포멧이든 다 된다. IEnumerator UploadProcessLocal() { bool bError = false; string bMsg = ""; PrintState("upload begin..."); // Get a reference to the storage service, using the default Firebase App Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance; // Create a storage reference from our storage service Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://eduplatform-97d55.appspot.com/"); // FireaBase 계정의 address 적는 곳. // Create a reference to 'images/mountains.jpg' // While the file names are the same, the references point to different files //mountains_ref.Name == mountain_images_ref.Name; // true //mountains_ref.Path == mountain_images_ref.Path; // false string local_file = ""; if (Application.platform == RuntimePlatform.Android) { local_file = "file:// " + Application.persistentDataPath + "/" + fileName; // android 휴대폰의 접근 가능한 로컬 주소 } else { local_file = "C:/Users/Gana/Downloads/project_stuff/" + fileName; // pc 의 로컬 주소.. } Firebase.Storage.StorageReference rivers_ref = storage_ref.Child("stuff/" + fileName); // 스토리지에 레퍼런스 먼저 만들기.. // metadata.. 추가할 것 이 있으면 추가,,, 필요 없을 시에 null 로.. //var new_metadata = new Firebase.Storage.MetadataChange(); //new_metadata.ContentType = "lyrics/text"; // 메타데이터 추가시에.... // Task TmpTask = rivers_ref.PutFileAsync(local_file, null, new Firebase.Storage.StorageProgress<Firebase.Storage.UploadState>(state => Task TmpTask = rivers_ref.PutFileAsync(local_file, null, new Firebase.Storage.StorageProgress <Firebase.Storage.UploadState>(state => { // Process 의 진행율을 보여주는 부분.. Debug.Log(string.Format("Progress: {0} of {1} bytes transferred.", state.BytesTransferred, state.TotalByteCount)); PercentView(state.BytesTransferred, state.TotalByteCount); }), System.Threading.CancellationToken.None, null).ContinueWith(task => { Debug.Log(string.Format("OnClickUpload::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted)); if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! bError = true; bMsg = "error: " + task.Exception.ToString(); } else if (task.IsCompleted) { // Metadata contains file metadata such as size, content-type, and download URL. Firebase.Storage.StorageMetadata metadata = task.Result; Debug.Log("Finished uploading..."); bError = false; } }); yield return(new WaitUntil(() => TmpTask.IsCompleted)); // 업로드가 완전히 완료된 후에 나머지를 처리한다. if (false == bError) { PrintState("upload complete..."); } else if (true == bError) { PrintState(bMsg); } }
public void Upload() { byte[] custom_bytes1 = t.EncodeToPNG(); byte[] custom_bytes2 = tt.EncodeToPNG(); byte[] custom_bytes3 = ttt.EncodeToPNG(); // Create a reference to the file you want to upload Firebase.Storage.StorageReference rivers_ref = storage_ref.Child(InputManager.ButtonName).Child("img1.png"); // Upload the file to the path "images/rivers.jpg" rivers_ref.PutBytesAsync(custom_bytes1) .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. Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.ToString(); // string download_url = metadata.DownloadUrl.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); } }); Firebase.Storage.StorageReference rivers_ref2 = storage_ref.Child(InputManager.ButtonName).Child("img2.png"); // Upload the file to the path "images/rivers.jpg" rivers_ref2.PutBytesAsync(custom_bytes2) .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. Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.ToString(); // string download_url = metadata.DownloadUrl.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); } }); Firebase.Storage.StorageReference rivers_ref3 = storage_ref.Child(InputManager.ButtonName).Child("img3.png"); rivers_ref3.PutBytesAsync(custom_bytes3) .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. Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.ToString(); // string download_url = metadata.DownloadUrl.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); } }); }