コード例 #1
0
    //================================================= 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...
    }
コード例 #2
0
    // 로컬 업로드 부분...
    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://fir-authtest22.appspot.com");                 // FireaBase 계정의 아이디 adress 적는 곳.
        // Create a reference to "mountains.jpg"
        //Firebase.Storage.StorageReference mountains_ref = storage_ref.Child("Test1/mountains.jpg");
        // Create a reference to 'images/mountains.jpg'
        //Firebase.Storage.StorageReference mountain_images_ref = storage_ref.Child("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";

        var TmpTask = rivers_ref.PutFileAsync(local_file, new_metadata, 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);
        }
    }