Firebase - Firestore Database와 Storage에 document와 사진 업로드하기

2025. 6. 12. 11:45·🔥 Firebase

Firebase

 

✅ Firestore Database


addDoc()

인자로 저장할 위치의 collection과 data를 받는다.

저장할 위치의 collection을 지정하기 위해 collection() 함수를 사용한다.

collection()

인자로 Firestore 인스턴스와 collection의 이름을 받는다.

      const doc = await addDoc(collection(db, "tweets"), {
        tweet,
        order: Date.now(),
        createdAt: FormatDate(),
        username: user.displayName || "Anonymous",
        userId: user.uid,
      });

 

✅ Storage


ref()

파일이 업로드 될 곳의 위치를 참조한다.

const locationRef = ref(storage, `tweets/${user.uid}/${doc.id}`);

uploadBytes()

인자로 참조 위치와 데이터를 받는다.

const uploadResult = await uploadBytes(locationRef, file);

getDownloadURL()

인자로 storage ref를 받는다.

이 함수는 uploadBytes()의 return 값의 public URL을 반환한다.

const url = await getDownloadURL(uploadResult.ref);

updateDoc()

인자로 업데이트 하고 싶은 문서의 참조와 데이터를 받는다.

await updateDoc(doc, {
	photoUrl: url,
});

'🔥 Firebase' 카테고리의 다른 글

Firebase - React Native iOS Setup  (0) 2026.02.26
Firebase - Rules  (0) 2025.06.20
Firebase - Hosting  (0) 2025.06.18
Firebase - query(), getDocs(), onSnapshot()을 사용해 Firestore DB에서 데이터를 가져오기  (0) 2025.06.16
Firebase - 이메일 & 비밀번호 로그인과 소셜 로그인(Github)  (0) 2025.06.09
'🔥 Firebase' 카테고리의 다른 글
  • Firebase - Rules
  • Firebase - Hosting
  • Firebase - query(), getDocs(), onSnapshot()을 사용해 Firestore DB에서 데이터를 가져오기
  • Firebase - 이메일 & 비밀번호 로그인과 소셜 로그인(Github)
j2yonghwa
j2yonghwa
Trying to be a fullstack developer 🚀
  • j2yonghwa
    j2yonghwa
    j2yonghwa
  • 전체
    오늘
    어제
    • 분류 전체보기 (156)
      • ⏰ Daily WakaTime (1)
      • 🏖️ 노마드코더 (2)
      • 🍺 Dev Setup (3)
      • 🔭 Tech Info (1)
      • 🚫 Error (1)
      • 📂 라이브러리 (23)
      • ♣️ Next.js 14 (10)
      • ♠️ Next.js 12 (20)
      • 🛸 React Native (12)
      • 🦋 TypeScript (1)
      • 🐍 Python (2)
      • 🌊 TailwindCSS (4)
      • 🧩 SQL (25)
      • 💎 Prisma (5)
      • 🌱 MongoDB (4)
      • 🎯 Redis (1)
      • 🧬 GraphQL (2)
      • 🔥 Firebase (7)
      • 💸 Third-Party Services (2)
      • 🕸️ Web (1)
      • 🏆 코딩테스트 (23)
      • 📙 모딥다 (5)
      • 📗 코테 합격자 되기 -JS- (0)
      • 📘 클린코드 (0)
      • 🍯 꿀팁 🐝 (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 깃헙
  • 공지사항

  • 인기 글

  • 태그

    PostgreSQL
    tailwindcss
    MySQL
    react router
    Next.js
    코딩테스트 입문
    모딥다
    mongoDB
    라이브러리
    자바스크립트
    Firebase
    next.js 12
    dev setup
    SQL
    next.js 14
    0레벨
    API
    Python
    Prisma
    React Native
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
j2yonghwa
Firebase - Firestore Database와 Storage에 document와 사진 업로드하기
상단으로

티스토리툴바