Apple प्लैटफ़ॉर्म पर Cloud Storage के लिए रेफ़रंस बनाना

आपकी फ़ाइलें इसमें सेव की जाती हैं Cloud Storage बकेट. कॉन्टेंट बनाने इस बकेट की फ़ाइलें एक पदानुक्रमिक संरचना में प्रस्तुत की जाती हैं, फ़ाइल सिस्टम या Firebase रीयल टाइम डेटाबेस के डेटा पर लागू होता है. किसी फ़ाइल का रेफ़रंस बनाने पर, आपका ऐप्लिकेशन उसे ऐक्सेस कर सकता है. ये रेफ़रंस इसके बाद, डेटा को अपलोड या डाउनलोड करने, मेटाडेटा को पाने या अपडेट करने या उसे मिटाने के लिए इस्तेमाल किया जा सकता है फ़ाइल से लिंक किया गया है. पहचान फ़ाइल, किसी खास फ़ाइल या उससे बड़े लेवल की जानकारी देती है नोड को क्रम में लगाएं.

अगर आपने Firebase रीयल टाइम डेटाबेस का इस्तेमाल किया है, तो इन पाथ को बहुत ज़्यादा जानते हैं. हालांकि, आपका फ़ाइल डेटा इसमें सेव किया जाता है Cloud Storage, रीयलटाइम डेटाबेस में नहीं है.

रेफ़रंस बनाना

फ़ाइल अपलोड करने, डाउनलोड करने या मिटाने के लिए, पहचान फ़ाइल बनाई जा सकती है. या इसके मेटाडेटा को पाने या अपडेट करने के लिए. रेफ़रंस इसे क्लाउड में मौजूद फ़ाइल का पॉइंटर माना जा सकता है. रेफ़रंस हैं कम वज़न वाला है, ताकि आप जितने चाहे उतने शॉर्ट वीडियो बना सकें. इन्हें इनके लिए भी फिर से इस्तेमाल किया जा सकता है: कई कार्रवाइयों के लिए इस्तेमाल किया जाता है.

संदर्भ FirebaseStorage सेवा का इस्तेमाल करके बनाए जाते हैं और इसके reference तरीका.

Swift

// 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()
    

Objective-C

// 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' कहें.

Swift

// 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)
    

Objective-C

// 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 ऊपर जाने के लिए नेविगेट करता है.

Swift

// 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()
    

Objective-C

// 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 है.

Swift

// 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()
    

Objective-C

// 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 प्रॉपर्टी का इस्तेमाल करके. ये प्रॉपर्टी फ़ाइल का पूरा पाथ, नाम, और बकेट की जानकारी देख सकते हैं.

Swift

// 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
    

Objective-C

// 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;
    

पहचान फ़ाइलों की सीमाएं

रेफ़रंस पाथ और नामों में, मान्य यूनिकोड वर्णों का कोई भी क्रम हो सकता है, लेकिन कुछ पाबंदियां लगाई गई हैं. इनमें ये शामिल हैं:

  1. UTF-8 कोड में बदलने पर,Reference.fullPath की कुल लंबाई 1 से 1024 बाइट के बीच होनी चाहिए.
  2. कोई नई लाइन शुरू करने का चिह्न या लाइन फ़ीड वर्ण नहीं.
  3. #, [, ], * या ? का इस्तेमाल करने से बचें, क्योंकि ये इनके साथ ठीक से काम नहीं करते Firebase रीयल टाइम डेटाबेस जैसे दूसरे टूल या gsutil.

पूरा उदाहरण

Swift

// 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()
    

Objective-C

// 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];
    

आइए, यह जानते हैं कि फ़ाइलें अपलोड करें Cloud Storage.