简体   繁体   中英

How to upload files to s3 via REST API

I am trying to use the REST API to upload large file fragments to S3. According to the documentation, I can get the uploadId required by Initiate Multipart Upload, but when I execute the second step Upload Part, I get the error message: SignatureDoesNotMatch, specifically As follows:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJSHB7UUBEBAA7R3Q</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA256
20190304T090043Z
20190304/ap-northeast-1/s3/aws4_request
af7e7ce5502f17450f855d48504417d144fae382e6cb02424b00f7a26447bfb9</StringToSign><SignatureProvided>738dd1ddf3d820890a460670e383e9a77f1a085f0db299ba0fc333ba98fc4613</SignatureProvided><StringToSignBytes>41 57 53 34 2d 4...</StringToSignBytes><CanonicalRequest>PUT
/201903/04/mYvQx4dHgY14A.f4v
partNumber=1&amp;uploadId=jpaQIecVCKdk9owl9_GARzhWzj__er1Xsm8gsuEFYW9YV6KTsPtsnf_b2x.TxV3Q.9oEWJhmd0NcG87YWGMM3u9ejpNhs5_xRIJ3khNCB4Wj1XGEzsNxGpJ.l21JwN0aAzkZBm_ZYwlGgkdjf8aJU.Q--
content-encoding:aws-chunked
content-type:application/octet-stream
host:bucketName.s3.ap-northeast-1.amazonaws.com
x-amz-content-sha256:3a71ba7ecd2ca6c45a1c55e501649fe0528cca013a41ec039a5d72d007196e49
x-amz-date:20190304T090043Z
x-amz-storage-class:REDUCED_REDUNDANCY

content-encoding;content-type;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class
3a71ba7ecd2ca6c45a1c55e501649fe0528cca013a41ec039a5d72d007196e49</CanonicalRequest><CanonicalRequestBytes>50 55 54 0a ...</CanonicalRequestBytes><RequestId>D05D18BA7169E142</RequestId><HostId>MX4bdbYIJNzuZXwqp+GrO0ToPbRdX0dYL/9aSrjA/2RpW0YItHAC52Rf1Tur9rcrlRNNYbVTI5E=</HostId></Error>

According to the documentation , StringToSign requires a CanonicalRequest only when getting the seed signature, and StringToSign requires a previouse-signature when doing a block upload.

My understanding is that seed signature generates Authorization, which is used to obtain the uploadId. During the block upload process, the signature is generated as follows to generate Authorization. I wonder if I understand it incorrectly?

块签名

Request information is as follows, I don't know what went wrong.

请求信息

Also, when building the signature, you need to set Content-Length and x-amz-decoded-content-length, but I didn't set it (because I don't know how to calculate the length of chunk-metadata), I'm not sure if they have to be set.

I also don't quite understand the chunk structure described in the documentation. How do I send this structure data?

string(IntHexBase(chunk-size)) + ";chunk-signature=" + signature + \r\n + chunk-data + \r\n

I hope I can get directions, thank you very much!

Set content-type to application/octet-stream put AWS auth key in Authorization header. I am providing reference link below which shows java example to upload file to s3 bucket

http://www.tothenew.com/blog/file-upload-on-amazon-s3-server-via-rest-api-call/

Installing the document to generate chunk signatures is difficult for me. I use seed signature to provide authorization for each chunk upload, which works unexpectedly. Regarding the signature, maybe I understand it wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM