Thuta Learning
Firebase Tutorial
AdvancedDevOps & Toolsintermediate

Download URL ရယူခြင်း

Download URL ရယူခြင်း

Upload လုပ်ပြီးတဲ့ file ကို browser မှာပြချင်ရင် download URL ရယူရပါမယ်။ Image preview, avatar display, downloadable file link တို့မှာအသုံးဝင်ပါတယ်။

Code Example

javascript
import { getStorage, ref, getDownloadURL } from 'firebase/storage';

const storage = getStorage();

async function getAvatarUrl(userId, fileName) {
  const fileRef = ref(storage, 'avatars/' + userId + '/' + fileName);
  const url = await getDownloadURL(fileRef);

  console.log('Download URL:', url);
  return url;
}

Expected usage

ရလာတဲ့ URL ကို <img src="url"> ထဲထည့်ပြီး image ပြနိုင်သလို Firestore ထဲမှာ avatarUrl အနေနဲ့သိမ်းထားနိုင်ပါတယ်။

သတိထားရန်

Download URL ကို public share လုပ်နိုင်တဲ့ token ပါဝင်နိုင်ပါတယ်။ Private file တွေအတွက် access design ကိုသေချာစဉ်းစားပါ။

Download URL ရယူခြင်း | Thuta Learning