본문으로 바로가기

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 등 이를 지원하는 패키지를 알아보시는 게 좋습니다.


darren, dev blog
블로그 이미지 DarrenKwonDev 님의 블로그
VISITOR 오늘 / 전체