Uploading to Amazon S3 via curl route

前端 未结 3 1965
被撕碎了的回忆
被撕碎了的回忆 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:34

        #run this code on ec2 linux with s3 write role 
    
    TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
    xamztoken=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/ec2files3 | jq -r ".Token"`
    
    
    yyyymmdd=`date +%Y%m%d`
    s3Bucket="testfiles3bc"
    bucketLocation="us-east-1"
    s3SecretKey=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/ec2files3 | jq -r '.SecretAccessKey'`
    s3AccessKey=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN"  http://169.254.169.254/latest/meta-data/iam/security-credentials/ec2files3 | jq -r ".AccessKeyId"`
    endpoint="testfiles3bc.s3.amazonaws.com"
    fileName="image.gif"
    contentLength=`cat ${fileName} | wc -c`
    contentHash=`openssl sha -sha256 -hex ${fileName} | sed 's/.* //'`
    contentType=`file -b --mime-type $fileName`
    b64=`openssl md5 -binary "$fileName" | openssl base64`
    acl="private"
    
    date=`date -u +%Y%m%dT%H%M%SZ`
    
    expdate_s="2022-12-30T12:00:00.000Z"
    
    region="us-east-1"
    
    
    p=$(cat <

提交回复
热议问题