C++ এর জন্য ক্লাউড স্টোরেজ সহ একটি ক্লাউড স্টোরেজ রেফারেন্স তৈরি করুন

আপনার ফাইলগুলি একটি ক্লাউড স্টোরেজ বালতিতে সংরক্ষণ করা হয়৷ আপনার স্থানীয় হার্ড ডিস্কের ফাইল সিস্টেম বা ফায়ারবেস রিয়েলটাইম ডেটাবেসের ডেটার মতো এই বালতিতে থাকা ফাইলগুলি একটি শ্রেণিবদ্ধ কাঠামোতে উপস্থাপন করা হয়। একটি ফাইলের একটি রেফারেন্স তৈরি করে, আপনার অ্যাপ এটিতে অ্যাক্সেস লাভ করে। এই রেফারেন্সগুলি তারপরে ডেটা আপলোড বা ডাউনলোড করতে, মেটাডেটা পেতে বা আপডেট করতে বা ফাইলটি মুছতে ব্যবহার করা যেতে পারে। একটি রেফারেন্স হয় একটি নির্দিষ্ট ফাইল বা অনুক্রমের একটি উচ্চ স্তরের নোড নির্দেশ করতে পারে।

আপনি যদি ফায়ারবেস রিয়েলটাইম ডেটাবেস ব্যবহার করে থাকেন তবে এই পথগুলি আপনার কাছে খুব পরিচিত বলে মনে হবে। যাইহোক, আপনার ফাইল ডেটা ক্লাউড স্টোরেজে সংরক্ষণ করা হয়, রিয়েলটাইম ডেটাবেসে নয়

একটি রেফারেন্স তৈরি করুন

একটি ফাইল আপলোড, ডাউনলোড বা মুছে ফেলার জন্য বা এর মেটাডেটা পেতে বা আপডেট করতে একটি রেফারেন্স তৈরি করুন৷ একটি রেফারেন্স ক্লাউডে একটি ফাইলের একটি পয়েন্টার হিসাবে চিন্তা করা যেতে পারে। রেফারেন্সগুলি হালকা, তাই আপনি যতগুলি প্রয়োজন ততগুলি তৈরি করতে পারেন৷ এগুলি একাধিক অপারেশনের জন্য পুনরায় ব্যবহারযোগ্য।

GetReferenceFromUrl() পদ্ধতিতে কল করে এবং gs://<your-cloud-storage-bucket> ফর্মের একটি URL পাস করে আপনার Firebase অ্যাপের storage পরিষেবা থেকে রেফারেন্স তৈরি করা হয়। আপনি Firebase কনসোলের স্টোরেজ বিভাগে এই URLটি খুঁজে পেতে পারেন।

// 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. # , [ , ] , * , বা ? , কারণ এগুলো অন্যান্য টুল যেমন ফায়ারবেস রিয়েলটাইম ডেটাবেস বা 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();

পরবর্তী পদক্ষেপ

এর পরে, আসুন শিখি কিভাবে ক্লাউড স্টোরেজে ফাইল আপলোড করতে হয়।