C++ के लिए Cloud Storage के साथ फ़ाइल मेटाडेटा का इस्तेमाल करना

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

फ़ाइल मेटाडेटा पाएं

फ़ाइल के मेटाडेटा में सामान्य प्रॉपर्टी मौजूद हैं. जैसे, name, size, और content_type (इन्हें अक्सर MIME टाइप कहा जाता है) और ये आम तौर पर कम इस्तेमाल होते हैं content_disposition और time_created जैसे फ़ॉर्मैट वाले. यह मेटाडेटा इनमें से कोई भी हो सकता है: GetMetadata का इस्तेमाल करके, Cloud Storage के रेफ़रंस से वापस लाया गया तरीका.

// Create reference to the file whose metadata we want to retrieve
StorageReference forest_ref = storage_ref.Child("images/forest.jpg");

// Get metadata properties
Future future = forest_ref.GetMetadata();

// Wait for Future to complete...

if (future.Error() != firebase::storage::kErrorNone) {
  // Uh-oh, an error occurred!
} else {
  // We can now retrieve the metadata for 'images/forest.jpg'
  Metadata* metadata = future.Result();
}

फ़ाइल मेटाडेटा अपडेट करें

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

// Create reference to the file whose metadata we 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
Future future = forest_ref.UpdateMetadata(new_metadata);

// Wait for Future to complete...

if (future.Error() != firebase::storage::kErrorNone) {
  // Uh-oh, an error occurred!
} else {
  // We 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
Future future = 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* custom_metadata = metadata.custom_metadata();
custom_metadata->insert(std::make_pair("location", "Yosemite, CA, USA");
custom_metadata->insert(std::make_pair("activity", "Hiking");

हर फ़ाइल के लिए, ऐप्लिकेशन से जुड़े डेटा को कस्टम मेटाडेटा में सेव किया जा सकता है. हालांकि, हम काफ़ी हद तक अपने डेटाबेस का इस्तेमाल करने की सलाह देते हैं (जैसे कि Firebase रीयल टाइम डेटाबेस) को डेटा शामिल है.

फ़ाइल मेटाडेटा की प्रॉपर्टी

फ़ाइल में मौजूद मेटाडेटा प्रॉपर्टी की पूरी सूची यहां दी गई है:

प्रॉपर्टी टाइप लिखा जा सकता है
bucket कॉन्स्ट वर्ण* नहीं
generation कॉन्स्ट वर्ण* नहीं
metageneration कॉन्स्ट वर्ण* नहीं
full_path कॉन्स्ट वर्ण* नहीं
name कॉन्स्ट वर्ण* नहीं
size int64_t नहीं
time_created int64_t नहीं
updated int64_t नहीं
cache_control कॉन्स्ट वर्ण* YES
content_disposition कॉन्स्ट वर्ण* YES
content_encoding कॉन्स्ट वर्ण* YES
content_language कॉन्स्ट वर्ण* YES
content_type कॉन्स्ट वर्ण* YES
download_urls std::वेक्टर<std::स्ट्रिंग> नहीं
custom_metadata std::map<std::स्ट्रिंग, std::string> YES

अगले चरण

फ़ाइलों को अपलोड, डाउनलोड, और अपडेट करना ज़रूरी है. हालांकि, इन सभी कामों के लिए, उन्हें हटाने के लिए. आइए, जानते हैं कि फ़ाइलें मिटाना Cloud Storage से.