অ্যাপল প্ল্যাটফর্মে একটি ক্লাউড স্টোরেজ রেফারেন্স তৈরি করুন

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

যদি আপনি Firebase Realtime Database ব্যবহার করে থাকেন, তাহলে এই পাথগুলি আপনার কাছে খুব পরিচিত মনে হবে। তবে, আপনার ফাইল ডেটা Cloud Storage সংরক্ষিত আছে, Realtime Database নয়

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

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

FirebaseStorage পরিষেবা এবং এর reference পদ্ধতি কল করে রেফারেন্স তৈরি করা হয়।

সুইফট

// Get a reference to the storage service using the default Firebase App
let storage = Storage.storage()

// Create a storage reference from our storage service
let storageRef = storage.reference()
    

অবজেক্টিভ-সি

// Get a reference to the storage service using the default Firebase App
FIRStorage *storage = [FIRStorage storage];

// Create a storage reference from our storage service
FIRStorageReference *storageRef = [storage reference];
    

আপনি বিদ্যমান রেফারেন্সে child পদ্ধতি ব্যবহার করে গাছের নীচের কোনও অবস্থানে, যেমন 'images/space.jpg' , একটি রেফারেন্স তৈরি করতে পারেন।

সুইফট

// Create a child reference
// imagesRef now points to "images"
let imagesRef = storageRef.child("images")

// Child references can also take paths delimited by '/'
// spaceRef now points to "images/space.jpg"
// imagesRef still points to "images"
var spaceRef = storageRef.child("images/space.jpg")

// This is equivalent to creating the full reference
let storagePath = "\(your_firebase_storage_bucket)/images/space.jpg"
spaceRef = storage.reference(forURL: storagePath)
    

অবজেক্টিভ-সি

// Create a child reference
// imagesRef now points to "images"
FIRStorageReference *imagesRef = [storageRef child:@"images"];

// Child references can also take paths delimited by '/'
// spaceRef now points to "images/space.jpg"
// imagesRef still points to "images"
FIRStorageReference *spaceRef = [storageRef child:@"images/space.jpg"];

// This is equivalent to creating the full reference
spaceRef = [storage referenceForURL:@"gs://<your-firebase-storage-bucket>/images/space.jpg"];
     

আমাদের ফাইল হায়ারার্কিতে আপনি parent এবং root পদ্ধতি ব্যবহার করে উপরে যেতে পারেন। parent এক স্তর উপরে নেভিগেট করে, যখন root সম্পূর্ণভাবে উপরে নেভিগেট করে।

সুইফট

// Parent allows us to move to the parent of a reference
// imagesRef now points to 'images'
let imagesRef = spaceRef.parent()

// Root allows us to move all the way back to the top of our bucket
// rootRef now points to the root
let rootRef = spaceRef.root()
    

অবজেক্টিভ-সি

// Parent allows us to move to the parent of a reference
// imagesRef now points to 'images'
imagesRef = [spaceRef parent];

// Root allows us to move all the way back to the top of our bucket
// rootRef now points to the root
FIRStorageReference *rootRef = [spaceRef root];
    

child , parent , এবং root একাধিকবার একসাথে শৃঙ্খলিত করা যেতে পারে, কারণ প্রতিটি একটি রেফারেন্স প্রদান করে। ব্যতিক্রম হল root এর parent , যা nil

সুইফট

// References can be chained together multiple times
// earthRef points to "images/earth.jpg"
let earthRef = spaceRef.parent()?.child("earth.jpg")

// nilRef is nil, since the parent of root is nil
let nilRef = spaceRef.root().parent()
    

অবজেক্টিভ-সি

// References can be chained together multiple times
// earthRef points to "images/earth.jpg"
FIRStorageReference *earthRef = [[spaceRef parent] child:@"earth.jpg"];

// nilRef is nil, since the parent of root is nil
FIRStorageReference *nilRef = [[spaceRef root] parent];
    

রেফারেন্স বৈশিষ্ট্য

fullPath , name , এবং bucket বৈশিষ্ট্য ব্যবহার করে আপনি রেফারেন্সগুলি পরিদর্শন করতে পারেন যাতে তারা যে ফাইলগুলি নির্দেশ করে তা আরও ভালভাবে বুঝতে পারে। এই বৈশিষ্ট্যগুলি ফাইলের সম্পূর্ণ পথ, নাম এবং bucket পায়।

সুইফট

// 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
    

অবজেক্টিভ-সি

// 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;
    

রেফারেন্সের উপর সীমাবদ্ধতা

রেফারেন্স পাথ এবং নামগুলিতে বৈধ ইউনিকোড অক্ষরের যেকোনো ক্রম থাকতে পারে, তবে কিছু বিধিনিষেধ আরোপ করা হয়েছে যার মধ্যে রয়েছে:

  1. UTF-8 এনকোড করার সময় reference.fullPath এর মোট দৈর্ঘ্য ১ থেকে ১০২৪ বাইটের মধ্যে হতে হবে।
  2. কোনও ক্যারেজ রিটার্ন বা লাইন ফিড অক্ষর নেই।
  3. # , [ , ] , * , অথবা ? ব্যবহার করা এড়িয়ে চলুন, কারণ এগুলি Firebase Realtime Database বা gsutil এর মতো অন্যান্য টুলের সাথে ভালোভাবে কাজ করে না।

সম্পূর্ণ উদাহরণ

সুইফট

// Points to the root reference
let storageRef = Storage.storage().reference()

// Points to "images"
let imagesRef = storageRef.child("images")

// Points to "images/space.jpg"
// Note that you can use variables to create child values
let fileName = "space.jpg"
let spaceRef = imagesRef.child(fileName)

// File path is "images/space.jpg"
let path = spaceRef.fullPath

// File name is "space.jpg"
let name = spaceRef.name

// Points to "images"
let images = spaceRef.parent()
    

অবজেক্টিভ-সি

// Points to the root reference
FIRStorageReference *storageRef = [[FIRStorage storage] reference];

// Points to "images"
FIRStorageReference *imagesRef = [storageRef child:@"images"];

// Points to "images/space.jpg"
// Note that you can use variables to create child values
NSString *fileName = @"space.jpg";
FIRStorageReference *spaceRef = [imagesRef child:fileName];

// File path is "images/space.jpg"
NSString *path = spaceRef.fullPath;

// File name is "space.jpg"
NSString *name = spaceRef.name;

// Points to "images"
imagesRef = [spaceRef parent];
    

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