আপনার ফাইলগুলি একটি ক্লাউড স্টোরেজ বালতিতে সংরক্ষণ করা হয়৷ আপনার স্থানীয় হার্ড ডিস্কের ফাইল সিস্টেম বা ফায়ারবেস রিয়েলটাইম ডেটাবেসের ডেটার মতো এই বালতিতে থাকা ফাইলগুলি একটি শ্রেণিবদ্ধ কাঠামোতে উপস্থাপন করা হয়। একটি ফাইলের একটি রেফারেন্স তৈরি করে, আপনার অ্যাপ এটিতে অ্যাক্সেস লাভ করে। এই রেফারেন্সগুলি তারপরে ডেটা আপলোড বা ডাউনলোড করতে, মেটাডেটা পেতে বা আপডেট করতে বা ফাইলটি মুছতে ব্যবহার করা যেতে পারে। একটি রেফারেন্স হয় একটি নির্দিষ্ট ফাইল বা অনুক্রমের একটি উচ্চ স্তরের নোড নির্দেশ করতে পারে।
আপনি যদি ফায়ারবেস রিয়েলটাইম ডেটাবেস ব্যবহার করে থাকেন তবে এই পথগুলি আপনার কাছে খুব পরিচিত বলে মনে হবে। যাইহোক, আপনার ফাইল ডেটা ক্লাউড স্টোরেজে সংরক্ষণ করা হয়, রিয়েলটাইম ডেটাবেসে নয় ।
একটি রেফারেন্স তৈরি করুন
ফাইল আপলোড বা ডাউনলোড করতে, ফাইলগুলি মুছতে বা মেটাডেটা পেতে বা আপডেট করতে, আপনি যে ফাইলটি পরিচালনা করতে চান তার একটি রেফারেন্স তৈরি করতে হবে৷ একটি রেফারেন্স ক্লাউডে একটি ফাইলের একটি পয়েন্টার হিসাবে চিন্তা করা যেতে পারে। রেফারেন্সগুলি হালকা, তাই আপনি যতগুলি প্রয়োজন ততগুলি তৈরি করতে পারেন এবং সেগুলি একাধিক ক্রিয়াকলাপের জন্য পুনরায় ব্যবহারযোগ্য।
একটি রেফারেন্স তৈরি করতে, getStorage()
ব্যবহার করে স্টোরেজ পরিষেবার একটি উদাহরণ পান তারপর একটি যুক্তি হিসাবে পরিষেবাটির সাথে ref()
কল করুন। এই রেফারেন্সটি আপনার ক্লাউড স্টোরেজ বাকেটের মূলের দিকে নির্দেশ করে।
Web modular API
import { getStorage, ref } from "firebase/storage"; // Get a reference to the storage service, which is used to create references in your storage bucket const storage = getStorage(); // Create a storage reference from our storage service const storageRef = ref(storage);
Web namespaced API
// Get a reference to the storage service, which is used to create references in your storage bucket var storage = firebase.storage(); // Create a storage reference from our storage service var storageRef = storage.ref();
আপনি গাছের নীচে একটি অবস্থানের জন্য একটি রেফারেন্স তৈরি করতে পারেন, ref()
কল করার সময় দ্বিতীয় আর্গুমেন্ট হিসাবে এই পাথে পাস করে 'images/space.jpg'
বলুন।
Web modular API
import { getStorage, ref } from "firebase/storage"; const storage = getStorage(); // Create a child reference const imagesRef = ref(storage, 'images'); // imagesRef now points to 'images' // Child references can also take paths delimited by '/' const spaceRef = ref(storage, 'images/space.jpg'); // spaceRef now points to "images/space.jpg" // imagesRef still points to "images"
Web namespaced API
// Create a child reference var imagesRef = storageRef.child('images'); // imagesRef now points to 'images' // Child references can also take paths delimited by '/' var spaceRef = storageRef.child('images/space.jpg'); // spaceRef now points to "images/space.jpg" // imagesRef still points to "images"
রেফারেন্স দিয়ে নেভিগেট করুন
ফাইলের অনুক্রমটি নেভিগেট করতে আপনি parent
এবং root
বৈশিষ্ট্যগুলিও ব্যবহার করতে পারেন। parent
একটি স্তরের উপরে নেভিগেট করে, যখন root
শীর্ষে সমস্ত পথ নেভিগেট করে।
Web modular API
import { getStorage, ref } from "firebase/storage"; const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // Parent allows us to move to the parent of a reference const imagesRef = spaceRef.parent; // imagesRef now points to 'images' // Root allows us to move all the way back to the top of our bucket const rootRef = spaceRef.root; // rootRef now points to the root
Web namespaced API
// Parent allows us to move to the parent of a reference var imagesRef = spaceRef.parent; // imagesRef now points to 'images' // Root allows us to move all the way back to the top of our bucket var rootRef = spaceRef.root; // rootRef now points to the root
child()
, parent
, এবং root
একসাথে একাধিকবার চেইন করা যেতে পারে, যেহেতু প্রতিটি একটি রেফারেন্স প্রদান করে। ব্যতিক্রম হল root
parent
যা null
।
Web modular API
import { getStorage, ref } from "firebase/storage"; const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // References can be chained together multiple times const earthRef = ref(spaceRef.parent, 'earth.jpg'); // earthRef points to 'images/earth.jpg' // nullRef is null, since the parent of root is null const nullRef = spaceRef.root.parent;
Web namespaced API
// References can be chained together multiple times var earthRef = spaceRef.parent.child('earth.jpg'); // earthRef points to 'images/earth.jpg' // nullRef is null, since the parent of root is null var nullRef = spaceRef.root.parent;
রেফারেন্স বৈশিষ্ট্য
fullPath
, name
, এবং bucket
বৈশিষ্ট্যগুলি ব্যবহার করে তারা যে ফাইলগুলি নির্দেশ করে তা আরও ভালভাবে বোঝার জন্য আপনি রেফারেন্সগুলি পরীক্ষা করতে পারেন৷ এই বৈশিষ্ট্যগুলি ফাইলের সম্পূর্ণ পথ, ফাইলের নাম এবং ফাইলটি যে বালতিতে সংরক্ষণ করা হয়েছে তা পায়।
Web modular API
import { getStorage, ref } from "firebase/storage"; const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // Reference's path is: 'images/space.jpg' // This is analogous to a file path on disk spaceRef.fullPath; // Reference's name is the last segment of the full path: 'space.jpg' // This is analogous to the file name spaceRef.name; // Reference's bucket is the name of the storage bucket where files are stored spaceRef.bucket;
Web namespaced API
// Reference's path is: 'images/space.jpg' // This is analogous to a file path on disk spaceRef.fullPath; // Reference's name is the last segment of the full path: 'space.jpg' // This is analogous to the file name spaceRef.name; // Reference's bucket is the name of the storage bucket where files are stored spaceRef.bucket;
রেফারেন্সের সীমাবদ্ধতা
রেফারেন্স পাথ এবং নামগুলিতে বৈধ ইউনিকোড অক্ষরের যেকোনো ক্রম থাকতে পারে, তবে কিছু বিধিনিষেধ আরোপ করা হয়েছে যার মধ্যে রয়েছে:
- UTF-8 এনকোড করার সময়
reference.fullPath
এর মোট দৈর্ঘ্য 1 থেকে 1024 বাইটের মধ্যে হতে হবে। - কোনো ক্যারেজ রিটার্ন বা লাইন ফিড অক্ষর নেই।
-
#
,[
,]
,*
, বা?
, কারণ এগুলো অন্যান্য টুল যেমন ফায়ারবেস রিয়েলটাইম ডেটাবেস বা gsutil- এর সাথে ভাল কাজ করে না।
সম্পূর্ণ উদাহরণ
Web modular API
import { getStorage, ref } from "firebase/storage"; const storage = getStorage(); // Points to the root reference const storageRef = ref(storage); // Points to 'images' const imagesRef = ref(storageRef, 'images'); // Points to 'images/space.jpg' // Note that you can use variables to create child values const fileName = 'space.jpg'; const spaceRef = ref(imagesRef, fileName); // File path is 'images/space.jpg' const path = spaceRef.fullPath; // File name is 'space.jpg' const name = spaceRef.name; // Points to 'images' const imagesRefAgain = spaceRef.parent;
Web namespaced API
// Points to the root reference var storageRef = firebase.storage().ref(); // Points to 'images' var imagesRef = storageRef.child('images'); // Points to 'images/space.jpg' // Note that you can use variables to create child values var fileName = 'space.jpg'; var spaceRef = imagesRef.child(fileName); // File path is 'images/space.jpg' var path = spaceRef.fullPath; // File name is 'space.jpg' var name = spaceRef.name; // Points to 'images' var imagesRef = spaceRef.parent;
এর পরে, আসুন শিখি কিভাবে ক্লাউড স্টোরেজে ফাইল আপলোড করতে হয়।