Cloud Storage रेफ़रंस में फ़ाइल अपलोड करने के बाद, फ़ाइल का मेटाडेटा भी पाया और अपडेट किया जा सकता है. उदाहरण के लिए, content_type प्रॉपर्टी को अपडेट करने के लिए. फ़ाइलों में, कस्टम की-वैल्यू पेयर भी सेव किए जा सकते हैं. इनमें फ़ाइल का अतिरिक्त मेटाडेटा भी शामिल होता है.
फ़ाइल का मेटाडेटा पाना
फ़ाइल के मेटाडेटा में name, size, और content_type (अक्सर एमआईएमई टाइप कहा जाता है) जैसी सामान्य प्रॉपर्टी के साथ-साथ, content_disposition और time_created जैसी कुछ कम सामान्य प्रॉपर्टी भी शामिल होती हैं. इस मेटाडेटा को GetMetadata तरीके का इस्तेमाल करके, Cloud Storage रेफ़रंस से वापस पाया जा सकता है.
// Create reference to the file whose metadata you want to retrieve StorageReference forest_ref = storage_ref.Child("images/forest.jpg"); // Get metadata properties Futurefuture = forest_ref.GetMetadata(); // Wait for Future to complete... if (future.Error() != firebase::storage::kErrorNone) { // Uh-oh, an error occurred! } else { // You can now retrieve the metadata for 'images/forest.jpg' Metadata* metadata = future.Result(); }
फ़ाइल का मेटाडेटा अपडेट करना
फ़ाइल अपलोड होने के बाद, UpdateMetadata तरीके का इस्तेमाल करके, फ़ाइल के मेटाडेटा को कभी भी अपडेट किया जा सकता है. किन प्रॉपर्टी को अपडेट किया जा सकता है, इस बारे में ज़्यादा जानने के लिए पूरी सूची देखें. मेटाडेटा में बताई गई प्रॉपर्टी ही अपडेट की जाती हैं. बाकी सभी प्रॉपर्टी में कोई बदलाव नहीं किया जाता.
// Create reference to the file whose metadata you want to change firebase::storage::StorageReference forest_ref = storage_ref.child("images/forest.jpg"); // Create file metadata to update Metadata new_metadata; newMetadata.set_cache_control("public,max-age=300"); newMetadata.set_content_type("image/jpeg"); // Update metadata properties Futurefuture = forest_ref.UpdateMetadata(new_metadata); // Wait for Future to complete... if (future.Error() != firebase::storage::kErrorNone) { // Uh-oh, an error occurred! } else { // You can now retrieve the updated metadata for 'images/forest.jpg' Metadata* metadata = future.Result(); }
खाली स्ट्रिंग पास करके, मेटाडेटा की ऐसी प्रॉपर्टी मिटाई जा सकती हैं जिनमें बदलाव किया जा सकता है:
// Create file metadata with property to delete StorageMetadata new_metadata; new_metadata.set_content_type(""); // Delete the metadata property Futurefuture = forest_ref.UpdateMetadata(new_metadata); // Wait for Future to complete... if (future.Error() != 0) { // Uh-oh, an error occurred! } else { // metadata.content_type() should be an empty string Metadata* metadata = future.Result(); }
गड़बड़ी ठीक करना
मेटाडेटा पाने या अपडेट करने में गड़बड़ियां होने की कई वजहें हो सकती हैं. जैसे, फ़ाइल का मौजूद न होना या उपयोगकर्ता के पास फ़ाइल को ऐक्सेस करने की अनुमति न होना. गड़बड़ियों के बारे में ज़्यादा जानने के लिए, गड़बड़ियों को ठीक करना लेख पढ़ें.
कस्टम मेटाडेटा
कस्टम मेटाडेटा को std::map के तौर पर तय किया जा सकता है. इसमें std::string प्रॉपर्टी शामिल होती हैं.
std::map<std::string, std::string>* custom_metadata = metadata.custom_metadata(); custom_metadata->insert(std::make_pair("location", "Yosemite, CA, USA"); custom_metadata->insert(std::make_pair("activity", "Hiking");
कस्टम मेटाडेटा में, हर फ़ाइल के लिए ऐप्लिकेशन से जुड़ा डेटा सेव किया जा सकता है. हालांकि, हमारा सुझाव है कि इस तरह के डेटा को सेव और सिंक करने के लिए, Firebase Realtime Database जैसे डेटाबेस का इस्तेमाल करें.
फ़ाइल के मेटाडेटा की प्रॉपर्टी
किसी फ़ाइल में मौजूद मेटाडेटा प्रॉपर्टी की पूरी सूची यहां दी गई है:
| प्रॉपर्टी | टाइप | लिखा जा सकता है |
|---|---|---|
bucket |
const char* | नहीं |
generation |
const char* | नहीं |
metageneration |
const char* | नहीं |
full_path |
const char* | नहीं |
name |
const char* | नहीं |
size |
int64_t | नहीं |
time_created |
int64_t | नहीं |
updated |
int64_t | नहीं |
cache_control |
const char* | YES |
content_disposition |
const char* | YES |
content_encoding |
const char* | YES |
content_language |
const char* | YES |
content_type |
const char* | YES |
download_urls |
std::vector<std::string> | नहीं |
custom_metadata |
std::map<std::string, std::string> | YES |
अगले चरण
फ़ाइलों को अपलोड, डाउनलोड, और अपडेट करना ज़रूरी है. हालांकि, उन्हें मिटाना भी ज़रूरी है. इसके बाद, Cloud Storage से फ़ाइलें मिटाने का तरीका जानें.