// 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..");
    }
    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);
            }
        });
    }
    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;
                    }
                });
            }
        });
    }
Exemple #4
0
    // Update is called once per frame
    public void Poster(Vector2d location, byte[] pic)
    {
        //init datapackage
        DataPackage package = new DataPackage();

        //write some datas
        package.latitude  = location.x;
        package.longitude = location.y;
        package.timeStamp = DateTime.Now.ToString("yyyyMMddhhmmss");

        //upload picture and get urls
        Firebase.Storage.StorageReference pngRef = storage_ref.Child("images").Child(package.timeStamp + ".png");

        // Upload the file to the path "images/rivers.jpg"
        pngRef.PutBytesAsync(pic)
        .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;
                pngRef.GetDownloadUrlAsync().ContinueWith((Task <Uri> task2) => {
                    if (!task2.IsFaulted && !task2.IsCanceled)
                    {
                        Debug.Log("Download URL: " + task2.Result);
                        // ... now download the file via WWW or UnityWebRequest.
                    }
                });
            }
        });
    }
Exemple #5
0
    public void takeAPic(Button button)
    {
        //disable button function
        button.interactable = false;
        try
        {
            webcamTexture.GetPixels32(colors);
            texture.SetPixels32(colors);
            texture.Apply();
            png = texture.EncodeToPNG();

            //init datapackage
            DataPackage package = new DataPackage();

            //write some datas
            package.latitude  = users.LocationProvider.CurrentLocation.LatitudeLongitude.x;
            package.longitude = users.LocationProvider.CurrentLocation.LatitudeLongitude.y;
            package.timeStamp = DateTime.Now.ToString("yyyyMMddhhmmss");

            //upload picture and get urls
            Firebase.Storage.StorageReference pngRef = storage_ref.Child("images").Child(package.timeStamp + ".png");

            // Upload the file to the path "images/rivers.jpg"
            pngRef.PutBytesAsync(png).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;
                    pngRef.GetDownloadUrlAsync().ContinueWith((Task <Uri> task2) =>
                    {
                        if (!task2.IsFaulted && !task2.IsCanceled)
                        {
                            Debug.Log("Download URL: " + task2.Result);
                            package.picURL = task2.Result.ToString();
                            string json    = JsonUtility.ToJson(package);
                            //make location of containing data
                            string key = reference.Child("Cat").Push().Key;
                            reference.Child("Cat").Child(key).SetRawJsonValueAsync(json);
                        }
                    });
                }
            });
        }
        catch (Exception e)
        {
            throw;
        }
        finally {
            //eable button function
            button.interactable = true;
        }
    }
Exemple #6
0
    public void clickUpload()
    {
        uploadPanel.SetActive(false);
        uploadStatus.SetActive(true);
        closeStatus.SetActive(false);

        status.text = "Sedang mempersiapkan file.";
        StartCoroutine(AnimateText());
        try {
            // 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://buddhist-festival-ar-2018.appspot.com");

            // Create a child reference
            // images_ref now points to "images"
            Firebase.Storage.StorageReference images_ref = storage_ref.Child("Lomba Foto/" + PlayerPrefs.GetString("Nama", "") + "_" + PlayerPrefs.GetString("Telepon", "") + "/" + SaveLoad.imageName[activeIndex]);

            // Data in memory
            byte[] custom_bytes = SaveLoad.imageTexture[activeIndex].EncodeToPNG();

            status.text = "Sedang Meng-upload Foto";

            // Create file metadata including the content type
            //Firebase.Storage.MetadataChange new_metadata = new Firebase.Storage.MetadataChange();
            //new_metadata.ContentType = "image/png";

            // Upload the file to the path "images/rivers.jpg"
            images_ref.PutBytesAsync(custom_bytes)
            .ContinueWith((task) => {
                if (task.IsFaulted || task.IsCanceled)
                {
                    //status.text = "Gagal mengupload foto.\n Pesan error:\n"+ task.Exception.ToString();
                    status.text = "Gagal mengupload foto.";
                    isanimate   = false;
                    closeStatus.SetActive(true);
                    // Uh-oh, an error occurred!
                }
                else
                {
                    // Metadata contains file metadata such as size, content-type, and download URL.
                    //Firebase.Storage.StorageMetadata metadata = task.Result;
                    status.text = "Upload selesai. Terima kasih sudah berpartisipasi dalam lomba foto.";
                    isanimate   = false;
                    closeStatus.SetActive(true);
                }
            });
        } catch (System.Exception ex) {
            //status.text = "Gagal mengupload foto.\n Pesan error:\n"+ ex.ToString();
            status.text = "Gagal mengupload foto.";
            isanimate   = false;
            closeStatus.SetActive(true);
        }
    }
    public void NextOnClick()
    {
        byte[] image = texture.EncodeToPNG();

        website  = websiteField.GetComponent <Text>().text;
        facebook = facebookField.GetComponent <Text>().text;
        linkedIn = linkedInField.GetComponent <Text>().text;
        phone    = phoneField.GetComponent <Text>().text;

        string card_id = PlayerPrefs.GetString("card_id");

        if (!string.IsNullOrEmpty(card_id))
        {
            if (!string.IsNullOrEmpty(website) && !string.IsNullOrEmpty(facebook) && !string.IsNullOrEmpty(linkedIn) && !string.IsNullOrEmpty(phone))
            {
                storage          = Firebase.Storage.FirebaseStorage.DefaultInstance;
                storageReference = storage.GetReferenceFromUrl("gs://card-677f1.appspot.com/augment_images/");
                Firebase.Storage.StorageReference targetReference = storageReference.Child(authUser.UserId + card_id);
                databaseReference = FirebaseDatabase.DefaultInstance.RootReference;

                targetReference.PutBytesAsync(image)
                .ContinueWith((Task <StorageMetadata> task) => {
                    if (task.IsFaulted || task.IsCanceled)
                    {
                        Debug.Log(task.Exception.ToString());
                        // Uh-oh, an error occurred!
                    }
                    else
                    {
                        targetReference.GetDownloadUrlAsync().ContinueWith((Task <Uri> uriTask) =>
                        {
                            string download_url = uriTask.Result.ToString();
                            Debug.Log("Finished uploading...");
                            Debug.Log("download url = " + download_url);
                            DatabaseReference childReference = databaseReference.Child("cards").Child(card_id);
                            childReference.Child("website").SetValueAsync(website);
                            childReference.Child("facebook").SetValueAsync(facebook);
                            childReference.Child("linkedIn").SetValueAsync(linkedIn);
                            childReference.Child("phone").SetValueAsync(phone);
                            childReference.Child("photo").SetValueAsync(download_url);
                        });
                    }
                });

                SceneManager.LoadScene("HomeScene");
            }

            else
            {
                print("ERROR IN FIELDS");
            }
        }
    }
    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;
                    }
                });
            }
        });
    }
    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);
                    }
                });
            }
        });
    }
Exemple #10
0
    /*
     * 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...");
            }
        });
    }
Exemple #11
0
    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);
            }
        });
    }
    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);
            }
        });
    }