आपकी फ़ाइलें Cloud Storage बकेट में सेव होती हैं. इस बकेट में मौजूद फ़ाइलों को हैरारकी के हिसाब से स्ट्रक्चर में दिखाया जाता है. यह ठीक वैसे ही होता है जैसे आपकी लोकल हार्ड डिस्क में मौजूद फ़ाइल सिस्टम या Firebase रीयल टाइम डेटाबेस में मौजूद डेटा होता है. किसी फ़ाइल का रेफ़रंस बनाने पर, आपका ऐप्लिकेशन उसे ऐक्सेस कर सकता है. इसके बाद, इन पहचान फ़ाइलों का इस्तेमाल डेटा को अपलोड या डाउनलोड करने, मेटाडेटा को पाने या अपडेट करने या फ़ाइल को मिटाने के लिए किया जा सकता है. रेफ़रंस फ़ाइल या तो किसी खास फ़ाइल या हैरारकी में बड़े लेवल की नोड हो सकती है.
अगर आपने Firebase रीयल टाइम डेटाबेस का इस्तेमाल किया है, तो ये पाथ आपको बहुत अच्छी तरह से मालूम होने चाहिए. हालांकि, आपकी फ़ाइल का डेटा Cloud Storage में सेव किया जाता है, न कि रीयलटाइम डेटाबेस में नहीं.
रेफ़रंस बनाना
किसी फ़ाइल को अपलोड करने, डाउनलोड करने या मिटाने या उसका मेटाडेटा पाने या अपडेट करने के लिए, पहचान फ़ाइल बनाई जा सकती है. रेफ़रंस फ़ाइल को क्लाउड में मौजूद फ़ाइल का पॉइंटर माना जा सकता है. पहचान फ़ाइलें हल्की होती हैं, इसलिए आप जितनी चाहे उतनी फ़ाइलें बना सकते हैं. ये कई कामों के लिए फिर से इस्तेमाल किए जा सकते हैं.
आपके Firebase ऐप्लिकेशन पर Firebase.Storage.FirebaseStorage
सेवा से पहचान फ़ाइलें बनाई जाती हैं. इसके लिए, GetReferenceFromUrl()
तरीके को कॉल करने के बाद, gs://<your-cloud-storage-bucket>
फ़ॉर्म का यूआरएल पास किया जाता है. आपको यह यूआरएल, Firebase कंसोल के स्टोरेज सेक्शन में मिलेगा.
// 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>");
ट्री में नीचे की जगह के लिए रेफ़रंस बनाया जा सकता है. उदाहरण के लिए, किसी मौजूदा पहचान फ़ाइल के लिए, child
तरीके का इस्तेमाल करके 'images/space.jpg'
.
// 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");
रेफ़रंस की मदद से नेविगेट करना
फ़ाइल की हैरारकी में ऊपर जाने के लिए, Parent
और Root
तरीकों का इस्तेमाल भी किया जा सकता है. Parent
एक लेवल ऊपर जाता है, जबकि Root
ऊपर की ओर नेविगेट करता है.
// 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
, और Root
को एक साथ कई बार जोड़ा जा सकता है, क्योंकि हर एक रेफ़रंस देता है. इसका अपवाद Root
का Parent
है, जो कि
अमान्य 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;
रेफ़रंस के तरीके
रेफ़रंस की जांच की जा सकती है, ताकि उन फ़ाइलों को बेहतर तरीके से समझा जा सके जो Path
, Name
, और Bucket
प्रॉपर्टी का इस्तेमाल करके रेफ़र की जाती हैं. इन प्रॉपर्टी में फ़ाइल का पूरा पाथ, नाम, और बकेट शामिल होती है.
// 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;
पहचान फ़ाइलों की सीमाएं
रेफ़रंस पाथ और नामों में मान्य यूनिकोड वर्णों का कोई भी क्रम हो सकता है, लेकिन कुछ पाबंदियां लागू होती हैं, जिनमें ये शामिल हैं:
- UTF-8 कोड में बदलने पर,
reference.Path
की कुल लंबाई 1 से 1024 बाइट के बीच होनी चाहिए. - कोई नई लाइन शुरू करने का चिह्न या लाइन फ़ीड वर्ण नहीं.
#
,[
,]
,*
या?
का इस्तेमाल करने से बचें, क्योंकि ये Firebase रीयल टाइम डेटाबेस या gsutil जैसे दूसरे टूल के साथ ठीक से काम नहीं करते.
पूरा उदाहरण
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;
अगले चरण
अब Cloud Storage में फ़ाइलें अपलोड करने का तरीका जानते हैं.