-
Notifications
You must be signed in to change notification settings - Fork 27
Object Storage
권영언 edited this page Jan 10, 2021
·
2 revisions
wave 프로젝트에서는 편집한 영상을 서버에 올려놓을 저장공간이 필요해서 사용함
Step1.사용 준비
- API 인증키 준비
- 마이페이지 > 계정관리 > 인증키 관리에서 API 인증키 생성 가능
- 이용 신청
- console에서 Object Storage 선택하여 생성
- 버킷 생성
- 버킷 이름 입력(객체에 대한 도메인에 활용됨,변경 불가)
- 버킷 공개 여부 선택
Step2. 사용(Javascript SDK)
- aws-sdk 사용 설치
npm i --save aws-sdk
update 로직
// AWS 설정
const endpoint = new AWS.Endpoint('https://kr.object.ncloudstorage.com');
const region = process.env.REGION;
const S3 = new AWS.S3({
endpoint,
region,
credentials: {
accessKeyId: process.env.ACCESS_KEY, // API 인증키
secretAccessKey: process.env.ACCESS_SECRET_KEY, // API인증키 비밀번호
},
});
/// upload
const upload = async (file: Express.Multer.File) => {
const folderName = `USER${USER_ID}`;
const fileId = uuidv5(file.originalname, uuidv5.URL);
const fileKey = encodeURI(`${folderName}/${fileId}`);
const {
$response: { httpResponse },
} = await S3.putObject({
Bucket: process.env.BUCKET_NAME,
Key: fileKey,
ACL: 'public-read',
Body: file.buffer,
}).promise();
문제) nCloud Object Storage CORS오류 -> local에서 서버에있는 동영상을 다운받으려니까 생김
해결) 버킷에 CORS를 설정해줘서 해결
postman에 Auth에 AWS signature를 이용해서 버킷에 CORS를 설정해주었다.
https://apidocs.gov-ncloud.com/ko/storage/object_storage/putbucketcors/ https://docs.ncloud.com/ko/storage/storage-8-4.html