C++ के लिए Cloud Storage के साथ Cloud Storage का रेफ़रंस बनाएं

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

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

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

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

आपके Firebase ऐप्लिकेशन पर storage सेवा से पहचान फ़ाइलें बनाई जाती हैं. इसके लिए: GetReferenceFromUrl() तरीके को कॉल करके फ़ॉर्म का यूआरएल पास करना gs://<your-cloud-storage-bucket>. आप इस यूआरएल को यहां देख सकते हैं: Firebase कंसोल का स्टोरेज सेक्शन.

// Get a reference to the storage service, using the default Firebase App
Storage* storage = Storage::GetInstance(app);

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

आपके पास ट्री में नीचे की जगह का रेफ़रंस बनाने का विकल्प है, मौजूदा संदर्भ पर child विधि का उपयोग करके 'images/space.jpg' कहें.

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

// Child references can also take paths delimited by '/'
// space_ref now points to "images/space.jpg"
// images_ref still points to "images"
StorageReference space_ref = storage_ref.Child("images/space.jpg");

// This is equivalent to creating the full reference
StorageReference space_ref = 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
// images_ref now points to 'images'
StorageReference images_ref = space_ref.Parent();

// Root allows us to move all the way back to the top of our bucket
// root_ref now points to the root
StorageReference root_ref = space_ref.Root();

Child, Parent, और Root को एक साथ कई बार जोड़ा जा सकता है, जैसे कि हर एक रेफ़रंस दिखाता है. इसका अपवाद Root का Parent है, जो एक अमान्य StorageReference है.

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

// null_ref is null, since the parent of root is an invalid StorageReference
StorageReference null_ref = space_ref.Root().Parent();

रेफ़रंस के तरीके

रेफ़रंस की जांच करके, उन फ़ाइलों को बेहतर तरीके से समझा जा सकता है जिनका इस्तेमाल वे रेफ़रंस के तौर पर करते हैं full_path, name, और bucket तरीके. इन तरीकों से फ़ाइल भर जाती है पाथ, नाम, और बकेट.

// Reference's path is: "images/space.jpg"
// This is analogous to a file path on disk
space_ref.full_path();

// Reference's name is the last segment of the full path: "space.jpg"
// This is analogous to the file name
space_ref.name();

// Reference's bucket is the name of the Cloud Storage bucket where files are stored
space_ref.bucket();

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

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

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

पूरा उदाहरण

Storage* storage = Storage::GetInstance(app);

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

// Points to "images"
StorageReference images_ref = storage_ref.Child("images");

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

// File path is "images/space.jpg"
std::string path = space_ref.full_path()

// File name is "space.jpg"
std::string name = space_ref.name()

// Points to "images"
StorageReference images_ref = space_ref.Parent();

अगले चरण

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