আপনার ফাইল Cloud Storage for Firebase বাকেটে স্টোর করা হয়। এই বাকেটের ফাইলগুলি একটি হায়ারার্কিক্যাল স্ট্রাকচারে উপস্থাপন করা হয়, ঠিক আপনার লোকাল হার্ড ডিস্কের ফাইল সিস্টেমের মতো।
কোনও ফাইলের রেফারেন্স তৈরি করার মাধ্যমে, আপনার অ্যাপ সেটির অ্যাক্সেস পায়। রেফারেন্স নির্দিষ্ট ফাইল বা হায়ারার্কির উচ্চ-লেভেল নোডকে পয়েন্ট করতে পারে। আপনি রেফারেন্সকে ক্লাউডে ফাইল বা নোডের পয়েন্টার হিসেবে ভাবতে পারেন। রেফারেন্স তৈরি করার পরে, আপনি এটি ব্যবহার করে অপারেশন (যেমন ডেটা আপলোড বা ডাউনলোড করা, মেটাডেটা পাওয়া বা আপডেট করা অথবা ফাইল মুছে ফেলা) সম্পন্ন করতে পারবেন।
এই পৃষ্ঠায় Cloud Storage for Firebase SDK ব্যবহার করে কীভাবে রেফারেন্স তৈরি করা ও কাজ করা যায় তা বর্ণনা করা হয়েছে।
রেফারেন্স তৈরি করা
কোনও ফাইলে অপারেশন করতে, আপনাকে প্রথমে ফাইলটির একটি রেফারেন্স তৈরি করতে হবে। রেফারেন্স লাইটওয়েট হয়, তাই আপনি যতগুলি প্রয়োজন ততগুলি তৈরি করতে পারবেন। এগুলি একাধিক অপারেশনের জন্য পুনর্ব্যবহারযোগ্য।
আপনার Firebase অ্যাপে storage পরিষেবা থেকে রেফারেন্স তৈরি করা হয়
GetReferenceFromUrl() পদ্ধতি কল করে এবং gs://<your-cloud-storage-bucket> ফর্মের URL পাস করে। আপনি এই URL Firebase কনসোল-এর
Storage বিভাগে খুঁজে পাবেন।
// Get a reference to the storage service, using the default Firebase App Storage* storage = Storage::GetInstance(app); // Create a Cloud Storage reference from the storage service StorageReference storage_ref = storage->GetReferenceFromUrl("gs://<your-cloud-storage-bucket>");
আপনি ট্রি-এর নিচের দিকে কোনও লোকেশনের রেফারেন্স তৈরি করতে পারবেন,
যেমন 'images/space.jpg', আগে থেকে থাকা রেফারেন্সে child পদ্ধতি ব্যবহার করে।
// 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 lets you move to the parent of a reference // images_ref now points to 'images' StorageReference images_ref = space_ref.Parent(); // Root lets you 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();
রেফারেন্সের উপর সীমাবদ্ধতা
রেফারেন্স পাথ এবং নামে যেকোনও ক্রমের সঠিক ইউনিকোড অক্ষর থাকতে পারে, তবে কিছু বিধিনিষেধ আরোপ করা হয়েছে, যার মধ্যে রয়েছে:
- UTF-8 এনকোড করা থাকলে reference.fullPath-এর মোট দৈর্ঘ্য ১ থেকে ১০২৪ বাইটের মধ্যে হতে হবে।
- কোনও নতুন লাইন বা লাইন ফিড অক্ষর নেই।
#,[,],*বা?ব্যবহার করা এড়িয়ে চলুন, কারণ এগুলি Firebase Realtime Database বা 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-এ জানুন।