/*
     * Method for publishing a recipe to firebase,
     * Takes in the recipe object that has all the inputted info from the recipe publishing page and a photo of the food
     * then sends the photo to storage and the recipe to our DB
     */
    public void PublishNewRecipe(Recipe recipe, string local_file)
    {
        FirebaseStorage storage = FirebaseStorage.DefaultInstance;
        string          key     = databaseReference.Child("recipes").Push().Key;

        // File located on disk
        Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://regen-66cf8.appspot.com/Recipes/" + key);
        // Create a reference to the file you want to upload
        storage_ref.PutFileAsync("file://" + local_file)
        .ContinueWith((Task <StorageMetadata> task) => {
            if (task.IsFaulted || task.IsCanceled)
            {
                Debug.Log(task.Exception.ToString());
            }
            else
            {
                Debug.Log("Finished uploading...");
            }
        });
        recipe.ImageReferencePath = $"gs://regen-66cf8.appspot.com/Recipes/" + key;

        string json = JsonUtility.ToJson(recipe);

        databaseReference.Child("recipes").Child(key).SetRawJsonValueAsync(json);

        NotificationManager.Instance.ShowNotification("Publish Successful");
    }
    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);
                }
            });
        }
    }
Exemple #3
0
    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);
            }
        });
    }
Exemple #4
0
    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);
            }
        });
    }
    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);
            }
        });
    }
Exemple #6
0
    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);
            }
        });
    }
    // 로컬 방식 업로드 부분... 로컬 방식이기 때문에 모든 포멧이든 다 된다.
    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);
        }
    }