티스토리 뷰
Firebase 이란 ? Firebase 사용 방법 - 저장소 , storage , bucket 사용 방법
YG - 96년생 , 강아지 있음, 개발자 희망 2022. 2. 23. 18:18시작하기
https://firebase.google.com/docs/storage/web/start?authuser=0
웹에서 Cloud Storage 시작하기 | Firebase Documentation
의견 보내기 웹에서 Cloud Storage 시작하기 Firebase용 Cloud Storage를 사용하면 이미지와 동영상 등 사용자 제작 콘텐츠를 업로드 및 공유하여 앱에 리치 미디어 콘텐츠를 빌드할 수 있습니다. 데이터
firebase.google.com
1. getStorage() 하기
import { initializeApp } from "firebase/app";
import { getStorage } from "firebase/storage";
// Set the configuration for your app
// TODO: Replace with your app's config object
const firebaseConfig = {
apiKey: '<your-api-key>',
authDomain: '<your-auth-domain>',
databaseURL: '<your-database-url>',
storageBucket: '<your-storage-bucket-url>'
};
const firebaseApp = initializeApp(firebaseConfig);
// Get a reference to the storage service, which is used to create references in your storage bucket
const storage = getStorage(firebaseApp);
2. 참조 만들기 , ref
파일을 저장할 위치를 정하는 것입니다.
import { ref } from 'firebase/storage';
const fileRef = ref(storageService, `${userObj.uid}/${uuidv4()}`);
https://firebase.google.com/docs/storage/web/create-reference?authuser=0
웹에서 Cloud Storage 참조 만들기 | Firebase Documentation
의견 보내기 웹에서 Cloud Storage 참조 만들기 파일은 Cloud Storage 버킷에 저장됩니다. 이 버킷의 파일은 로컬 하드 디스크의 파일 시스템 또는 Firebase 실시간 데이터베이스의 데이터와 같이 계층 구
firebase.google.com
3. 파일 업로드하기
문자열로 올릴 시 uploadString을 사용하며( 파일 ref , 보낼 파일 데이터 , 포맷 ) 순서로 코드를 작성하면 됩니다
import { ref, uploadString } from 'firebase/storage';
const response = await uploadString(fileRef, photoSource, 'data_url');
https://firebase.google.com/docs/storage/web/upload-files?authuser=0
웹에서 Cloud Storage로 파일 업로드 | Firebase Documentation
의견 보내기 웹에서 Cloud Storage로 파일 업로드 Firebase용 Cloud Storage를 사용하면 Firebase에서 제공하고 관리하는 Cloud Storage 버킷에 파일을 빠르고 손쉽게 업로드할 수 있습니다. 참고: 기본적으로 Clo
firebase.google.com
혹시 업로드가 되지 않는다면 규칙에서 다음과 같이 바꿔보세요
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}


4. 파일 다운로드 받기 (이미지 파일 URL 얻기)
getDownloadURL ( 파일 업로드할 때 했던 uploadString의 객체를 인자로 넣고. ref를 하면 이미지 주소가 나옵니다)
https://firebase.google.com/docs/storage/web/download-files
웹에서 Cloud Storage로 파일 다운로드 | Firebase Documentation
의견 보내기 웹에서 Cloud Storage로 파일 다운로드 Firebase용 Cloud Storage를 사용하면 Firebase에서 제공하고 관리하는 Cloud Storage 버킷에서 파일을 빠르고 손쉽게 다운로드할 수 있습니다. 참고: 기본적
firebase.google.com
import { getDownloadURL, ref, uploadString } from 'firebase/storage';
let photoURL = '';
if (photoSource !== '') {
const fileRef = ref(storageService, `${userObj.uid}/${uuidv4()}`);
const response = await uploadString(fileRef, photoSource, 'data_url');
photoURL = await getDownloadURL(response.ref);


5. 파일 삭제
deleteObject을 이용해서 삭제하면 됩니다.
import { dbService, storageService } from '../firebase';
import { deleteObject, ref } from 'firebase/storage';
await deleteObject(ref(storageService, photoURL));
https://firebase.google.com/docs/storage/web/delete-files
웹에서 Cloud Storage로 파일 삭제 | Firebase Documentation
의견 보내기 웹에서 Cloud Storage로 파일 삭제 Cloud Storage에 파일을 업로드한 후 파일을 삭제할 수도 있습니다. 참고: 기본적으로 Cloud Storage 버킷으로 버킷의 데이터 또는 파일에서 작업을 수행하려
firebase.google.com
'react' 카테고리의 다른 글
React에서 ApolloGraphQL을 사용한 graphQL 사용 방법 (5) | 2023.04.17 |
---|---|
No routes matched location "/" 에러 해결 방법, error ,react-router-dom (0) | 2022.02.25 |
Firebase 이란 ? Firebase 사용 방법 - 데이터 저장 ,삭제,수정 (0) | 2022.02.21 |
Firebase 이란 ? Firebase 사용 방법 - 사용자 인증편(로그인,로그아웃,프로필 수정) (0) | 2022.02.20 |
react-redux 설치 및 이용방법 (0) | 2022.02.11 |
- Total
- Today
- Yesterday
- 프리온보딩
- error
- nextjs
- nodejs
- C언어
- React
- 우아한테크코스
- import/order
- Storybook
- 스토리 북
- 노마드코더
- 원티드
- 노개북
- electron
- NextRequest
- env
- 아차산
- 윤성우 열혈C프로그래밍
- javascript
- 위코드
- TopLayer
- CLASS
- WSL2
- createPortal
- NextApiRequest
- jest
- 프론트앤드
- 초보
- 북클럽
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |