AWS로 치면 S3와 같이 무언가를 저장하는 역할이다.
Google Cloud Storage는 비구조화 객체를 위한 강력하고 경제적인 저장소 솔루션으로서 라이브 웹 콘텐츠 호스팅에서 분석용 데이터 저장, 보관처리, 백업 등에 이르기까지 다양한 용도에 적합합니다.
메뉴에서 Storage를 열고 S3와 같이 이것저것 설정해주면 됩니다.
Bucket - Documentation
Enable logging functionality for this bucket. This will make two API requests, first to grant Cloud Storage WRITE permission to the bucket, then to set the appropriate configuration on the Bucket's metadata.
googleapis.dev
다음과 같이 구성하여 strage에 파일을 올릴 수 있습니다.
const { Storage } = require('@google-cloud/storage')
const dotenv = require('dotenv').config()
const { BUCKET_NAME } = process.env
// 스토리지 인스턴스 생성
const storage = new Storage({ keyFilename: 'key.json' })
await storage.bucket(BUCKET_NAME).upload(filename, {
gzip: true,
destination: filename,
metadata: {
cacheControl: 'public, max-age=31536000',
},
}, (err, file) => {
if (err) return res.json{err: err.message}
return res.json{...}
})
만약 업로드 이전에 리사이징 등 처리가 필요하면 multer-sharp 등 이를 지원하는 패키지를 알아보시는 게 좋습니다.
'GCP > ☁️ GCP' 카테고리의 다른 글
Google Compute Engine (3): GCE 기본적 운영 (일정, OS patch/policy, NEG ...) (0) | 2021.09.14 |
---|---|
Google Compute Engine (2) : GCE Network 기초 (VPC, Subnet) (0) | 2021.09.12 |
Google Compute Engine (1) : GCE 생성 및 접근 (0) | 2021.09.12 |
GCP의 Region/Zone, 리소스 계층 구조 (0) | 2021.09.10 |
Dialogflow API (0) | 2020.09.22 |