Unity için Cloud Storage ile Cloud Storage referansı oluşturma

Dosyalarınız şurada depolanır: Cloud Storage paketinden yararlanın. İlgili içeriği oluşturmak için kullanılan bu paketteki dosyalar tıpkı sizin gibi hiyerarşik bir yapıda sunulur yerel sabit diskinizdeki dosya sistemi veya Firebase Realtime Database'deki veriler. Bir dosyaya referans oluşturduğunuzda uygulamanız ilgili dosyaya erişim kazanır. Bu referanslar Veri yüklemek veya indirmek, meta verileri almak ya da güncellemek ya da verileri silmek için kullanılabilir. seçin. Referans, belirli bir dosyaya veya daha üst bir düzeye işaret edebilir. düğümünü aratın.

Firebase Realtime Database'i kullandıysanız bu yollar size tanıdık gelebilir. Ancak dosya verileriniz şurada saklanır: Cloud Storage, Realtime Database'de değil.

Referans Oluşturma

Dosya yüklemek, indirmek veya silmek için referans oluşturma, veya meta verilerini almak ya da güncellemek için kullanılır. Referans , buluttaki bir dosyaya işaret eden bir işaret olarak düşünülebilir. Referanslar: hafif, böylece ihtiyacınız olduğu kadar oluşturabilirsiniz. Bunlar ayrıca yeniden kullanılabilir birden fazla işlem yapabilirsiniz.

Referanslar şurada Firebase.Storage.FirebaseStorage hizmetinden oluşturulur: Firebase uygulamanızı GetReferenceFromUrl() yöntemini çağırıp gs://<your-cloud-storage-bucket> formunun URL'si. Bu URL'yi şurada bulabilirsiniz: Firebase konsolunun Depolama alanı.

// Get a reference to the storage service, using the default Firebase App
FirebaseStorage storage = FirebaseStorage.DefaultInstance;

// Create a storage reference from our storage service
StorageReference storageRef =
    storage.GetReferenceFromUrl("gs://<your-cloud-storage-bucket>");

Örneğin, ağaçta daha aşağıda bir konum için referans oluşturabilirsiniz. 'images/space.jpg': Mevcut bir referansta child yöntemini kullanarak.

// Create a child reference
// imagesRef now points to "images"
StorageReference imagesRef = storageRef.Child("images");

// Child references can also take paths delimited by '/' such as:
// "images/space.jpg".
StorageReference spaceRef = imagesRef.Child("space.jpg");
// spaceRef now points to "images/space.jpg"
// imagesRef still points to "images"

// This is equivalent to creating the full referenced
StorageReference spaceRefFull = storage.GetReferenceFromUrl(
    "gs://<your-cloud-storage-bucket>/images/space.jpg");

Dosyamızda yukarı gitmek için Parent ve Root yöntemlerini de kullanabilirsiniz hiyerarşik olarak düzenlenmiştir. Parent bir seviye yukarı giderken Root tamamen gider dokunun.

// Parent allows us to move to the parent of a reference
// imagesRef now points to 'images'
StorageReference imagesRef = spaceRef.Parent;

// Root allows us to move all the way back to the top of our bucket
// rootRef now points to the root
StorageReference rootRef = spaceRef.Root;

Child, Parent ve Root, aşağıdaki gibi birden çok kez zincirlenebilir: her biri bir başvuru döndürür. Bunun istisnası, Root metriğinin Parent. geçersiz bir StorageReference.

// References can be chained together multiple times
// earthRef points to "images/earth.jpg"
StorageReference earthRef =
    spaceRef.Parent.Child("earth.jpg");

// nullRef is null since the parent of root is an invalid StorageReference
StorageReference nullRef = spaceRef.Root.Parent;

Referans Yöntemleri

Yönlendirdikleri dosyaları daha iyi anlamak için referansları incelemek için Path, Name ve Bucket özellikleri. Bu özellikler dosyanın tam yol, ad ve paket.

// Reference's path is: "images/space.jpg"
// This is analogous to a file path on disk
string path = spaceRef.Path;

// Reference's name is the last segment of the full path: "space.jpg"
// This is analogous to the file name
string name = spaceRef.Name;

// Reference's bucket is the name of the storage bucket where files are stored
string bucket = spaceRef.Bucket;

Referanslarla ilgili Sınırlamalar

Referans yolları ve adları, geçerli Unicode karakterlerinden oluşan herhangi bir diziyi içerebilir. ancak aşağıdakileri de içeren belirli kısıtlamalar uygulanır:

  1. UTF-8 olduğunda toplam reference.Path uzunluğu 1 ile 1.024 bayt arasında olmalıdır kodlanmıştır.
  2. Satır Başı veya Satır Feed'i karakterleri yok.
  3. #, [, ], * veya ? ile iyi sonuç vermediğinden bunları kullanmaktan kaçının. Firebase Realtime Database gibi diğer araçlar veya gsutil.

Tam Örnek

FirebaseStorage storage = FirebaseStorage.DefaultInstance;

// Points to the root reference
StorageReference storageRef =
    storage.GetReferenceFromUrl("gs://<your-bucket-name>");

// Points to "images"
StorageReference imagesRef = storageRef.Child("images");

// Points to "images/space.jpg"
// Note that you can use variables to create child values
string filename = "space.jpg";
StorageReference spaceRef = imagesRef.Child(filename);

// File path is "images/space.jpg"
string path = spaceRef.Path;

// File name is "space.jpg"
string name = spaceRef.Name;

// Points to "images"
StorageReference imagesRef = spaceRef.Parent;

Sonraki adımlar

Şimdi de bir proje yöneticisinin dosyaları yükle Cloud Storage.