आपकी फ़ाइलें क्लाउड स्टोरेज बकेट में संग्रहीत हैं। इस बकेट में फ़ाइलें एक पदानुक्रमित संरचना में प्रस्तुत की जाती हैं, जैसे आपकी स्थानीय हार्ड डिस्क पर फ़ाइल सिस्टम, या फ़ायरबेस रीयलटाइम डेटाबेस में डेटा। किसी फ़ाइल का संदर्भ बनाकर, आपका ऐप उस तक पहुंच प्राप्त करता है। फिर इन संदर्भों का उपयोग डेटा अपलोड या डाउनलोड करने, मेटाडेटा प्राप्त करने या अपडेट करने या फ़ाइल को हटाने के लिए किया जा सकता है। एक संदर्भ या तो किसी विशिष्ट फ़ाइल या पदानुक्रम में उच्च स्तरीय नोड को इंगित कर सकता है।
यदि आपने फायरबेस रीयलटाइम डेटाबेस का उपयोग किया है, तो ये पथ आपको बहुत परिचित लगेंगे। हालाँकि, आपका फ़ाइल डेटा क्लाउड स्टोरेज में संग्रहीत है, रीयलटाइम डेटाबेस में नहीं ।
एक संदर्भ बनाएँ
किसी फ़ाइल को अपलोड करने, डाउनलोड करने या हटाने या उसका मेटाडेटा प्राप्त करने या अपडेट करने के लिए एक संदर्भ बनाएं। एक संदर्भ को क्लाउड में किसी फ़ाइल के सूचक के रूप में माना जा सकता है। संदर्भ हल्के होते हैं, इसलिए आप जितनी चाहें उतनी बना सकते हैं। वे कई कार्यों के लिए पुन: प्रयोज्य भी हैं।
संदर्भ FirebaseStorage
सेवा का उपयोग करके और इसकी reference
विधि को कॉल करके बनाए जाते हैं।
तीव्र
// Get a reference to the storage service using the default Firebase App let storage = Storage.storage() // Create a storage reference from our storage service let storageRef = storage.reference()
उद्देश्य सी
// Get a reference to the storage service using the default Firebase App FIRStorage *storage = [FIRStorage storage]; // Create a storage reference from our storage service FIRStorageReference *storageRef = [storage reference];
आप किसी मौजूदा संदर्भ पर child
विधि का उपयोग करके, पेड़ के नीचे किसी स्थान का संदर्भ बना सकते हैं, जैसे 'images/space.jpg'
।
तीव्र
// Create a child reference // imagesRef now points to "images" let imagesRef = storageRef.child("images") // Child references can also take paths delimited by '/' // spaceRef now points to "images/space.jpg" // imagesRef still points to "images" var spaceRef = storageRef.child("images/space.jpg") // This is equivalent to creating the full reference let storagePath = "\(your_firebase_storage_bucket)/images/space.jpg" spaceRef = storage.reference(forURL: storagePath)
उद्देश्य सी
// Create a child reference // imagesRef now points to "images" FIRStorageReference *imagesRef = [storageRef child:@"images"]; // Child references can also take paths delimited by '/' // spaceRef now points to "images/space.jpg" // imagesRef still points to "images" FIRStorageReference *spaceRef = [storageRef child:@"images/space.jpg"]; // This is equivalent to creating the full reference spaceRef = [storage referenceForURL:@"gs://<your-firebase-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' let imagesRef = spaceRef.parent() // Root allows us to move all the way back to the top of our bucket // rootRef now points to the root let rootRef = spaceRef.root()
उद्देश्य सी
// Parent allows us to move to the parent of a reference // imagesRef now points to 'images' imagesRef = [spaceRef parent]; // Root allows us to move all the way back to the top of our bucket // rootRef now points to the root FIRStorageReference *rootRef = [spaceRef root];
child
, parent
और root
कई बार एक साथ जोड़ा जा सकता है, क्योंकि प्रत्येक एक संदर्भ देता है। अपवाद root
का parent
है, जो nil
है।
तीव्र
// References can be chained together multiple times // earthRef points to "images/earth.jpg" let earthRef = spaceRef.parent()?.child("earth.jpg") // nilRef is nil, since the parent of root is nil let nilRef = spaceRef.root().parent()
उद्देश्य सी
// References can be chained together multiple times // earthRef points to "images/earth.jpg" FIRStorageReference *earthRef = [[spaceRef parent] child:@"earth.jpg"]; // nilRef is nil, since the parent of root is nil FIRStorageReference *nilRef = [[spaceRef root] parent];
संदर्भ गुण
आप fullPath
, name
और bucket
गुणों का उपयोग करके उन फ़ाइलों को बेहतर ढंग से समझने के लिए संदर्भों का निरीक्षण कर सकते हैं जिन्हें वे इंगित करते हैं। इन गुणों से फ़ाइल का पूरा पथ, नाम और बकेट मिलता है।
तीव्र
// Reference's path is: "images/space.jpg" // This is analogous to a file path on disk spaceRef.fullPath // Reference's name is the last segment of the full path: "space.jpg" // This is analogous to the file name spaceRef.name // Reference's bucket is the name of the storage bucket where files are stored spaceRef.bucket
उद्देश्य सी
// Reference's path is: "images/space.jpg" // This is analogous to a file path on disk spaceRef.fullPath; // Reference's name is the last segment of the full path: "space.jpg" // This is analogous to the file name spaceRef.name; // Reference's bucket is the name of the storage bucket where files are stored spaceRef.bucket;
सन्दर्भों पर सीमाएँ
संदर्भ पथों और नामों में वैध यूनिकोड वर्णों का कोई भी क्रम हो सकता है, लेकिन कुछ प्रतिबंध लगाए गए हैं जिनमें शामिल हैं:
- UTF-8 एन्कोड होने पर reference.fullPath की कुल लंबाई 1 और 1024 बाइट्स के बीच होनी चाहिए।
- कोई कैरिज रिटर्न या लाइन फ़ीड वर्ण नहीं।
-
#
,[
,]
,*
, या?
का उपयोग करने से बचें , क्योंकि ये फायरबेस रीयलटाइम डेटाबेस या gsutil जैसे अन्य टूल के साथ अच्छी तरह से काम नहीं करते हैं।
पूर्ण उदाहरण
तीव्र
// Points to the root reference let storageRef = Storage.storage().reference() // Points to "images" let imagesRef = storageRef.child("images") // Points to "images/space.jpg" // Note that you can use variables to create child values let fileName = "space.jpg" let spaceRef = imagesRef.child(fileName) // File path is "images/space.jpg" let path = spaceRef.fullPath // File name is "space.jpg" let name = spaceRef.name // Points to "images" let images = spaceRef.parent()
उद्देश्य सी
// Points to the root reference FIRStorageReference *storageRef = [[FIRStorage storage] reference]; // Points to "images" FIRStorageReference *imagesRef = [storageRef child:@"images"]; // Points to "images/space.jpg" // Note that you can use variables to create child values NSString *fileName = @"space.jpg"; FIRStorageReference *spaceRef = [imagesRef child:fileName]; // File path is "images/space.jpg" NSString *path = spaceRef.fullPath; // File name is "space.jpg" NSString *name = spaceRef.name; // Points to "images" imagesRef = [spaceRef parent];
आगे, आइए जानें कि क्लाउड स्टोरेज पर फ़ाइलें कैसे अपलोड करें ।