Download to Amazon S3 using cURL / libcurl

I'm currently trying to develop an application to upload files to an Amazon S3 bucket using cURL and C ++. After carefully reading the manual for S3 developers, I began to implement my application using cURL and formed a header as described in the developer manual, and after many tests and errors to determine the best way to create an S3 signature, I now encountered error 501 The resulting header suggests that the method I use is not implemented. I am not sure where I am going wrong, but here is the HTTP header that I am sending to Amazon:

PUT /test1.txt HTTP/1.1 Accept: */* Transfer-Encoding: chunked Content-Type: text/plain Content-Length: 29 Host: [BucketName].s3.amazonaws.com Date: [Date] Authorization: AWS [Access Key ID]:[Signature] Expect: 100-continue 

My bucket name, passkey identifier, and signature are shortened for security reasons.

I'm not sure what I'm doing wrong, but I think the error is due to the Accept and Transfer-Encoding fields (not quite right). So can someone tell me what I'm doing wrong or why I get 501.

+6
c ++ windows curl amazon-s3 libcurl
source share
2 answers

Solved: CURLOPT was missing for the file size in my code, and now everything works fine

-one
source share

You can execute the bash file. Here is an example upload.sh script that you can simply run as: sh upload.sh yourfile

 #!/bin/bash file=$1 bucket=YOUR_BUCKET resource="/${bucket}/${file}" contentType="application/x-itunes-ipa" dateValue=`date -R` stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}" s3Key=YOUR_KEY_HERE s3Secret=YOUR_SECRET echo "SENDING TO S3" signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64` curl -vv -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} 

further: http://www.jamesransom.net/?p=58

http://www.jamesransom.net/?p=58

+3
source share

All Articles