Uploading to Amazon S3 via curl route

前端 未结 3 1970
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 01:13

I am trying to set up a file upload REST API via Spring Boot.

I currently have a list/GET method curl http://localhost:8080/api/aws/s3/list which retur

3条回答
  •  一个人的身影
    2021-01-02 01:39

    You should specify your using bucket name and some parameters for S3. And I guess it's PUT, not POST. There are several command line samples in the internet.

    file=/path/to/file/to/upload.tar.gz
    bucket=your-bucket
    resource="/${bucket}/${file}"
    contentType="application/x-compressed-tar"
    dateValue=`date -R`
    stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
    s3Key=xxxxxxxxxxxxxxxxxxxx
    s3Secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
    curl -X PUT -T "${file}" \
      -H "Host: ${bucket}.s3.amazonaws.com" \
      -H "Date: ${dateValue}" \
      -H "Content-Type: ${contentType}" \
      -H "Authorization: AWS ${s3Key}:${signature}" \
      https://${bucket}.s3.amazonaws.com/${file}
    
    • Uploading to S3 in 18 lines of Shell (used to upload builds for http://soltrader.net)
    • Uploading to S3 in Bash

提交回复
热议问题