Print
카테고리: [ Amazon Web Services ]
조회수: 2112

1. 개요

S3 버킷에 파일을 업로드하는 REST API

2. 스크립트

date=`date +%Y%m%d`
dateFormatted=`date -R`

s3Bucket="${3}"
fileName="${4}"

relativePath="/${s3Bucket}/${fileName}"
contentType="application/octet-stream"
stringToSign="PUT\n\n${contentType}\n${dateFormatted}\n${relativePath}"
s3AccessKey="${1}"
s3SecretKey="${2}"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3SecretKey} -binary | base64`

curl -X PUT -T "${fileName}" \
-H "Host: ${s3Bucket}.s3.amazonaws.com" \
-H "Date: ${dateFormatted}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3AccessKey}:${signature}" \
http://${s3Bucket}.s3.amazonaws.com/${fileName}

3. 실행

입력값은 총 4개이다

  1. access key
  2. secrect access key
  3. 버킷 이름
  4. 파일 이름

4. 참고

http://www.tothenew.com/blog/file-upload-on-amazon-s3-server-using-curl-request/