Edele Gizatullin
Edele Gizatullin

Reputation: 5

Can't upload to Amazon S3 with signed request via XMLHttpRequest

I did everything as Heroku recommended, but I keep getting SignatureDoesNotMatch error. With message:

The request signature we calculated does not
match the signature you provided. Check your key
and signing method.

But I did'n mean to sign anything. I just want a link that I can direct download a file to.

Here are my aws config at Node JS server. I use them to generate a signed request. They provide me with a long link.

var s3_params = {
  Bucket: S3_BUCKET,
  Key: filename,
  Expires: 400,
  ContentType: fileType,
  ACL: 'public-read'
}

Am I right thinking that I don't need to have AWS secret key to upload a file with signed request?

Upvotes: 0

Views: 332

Answers (2)

Edele Gizatullin
Edele Gizatullin

Reputation: 5

The issue was in wrong credentials. I just forgot, that I deleted my secret key from AWS. I have recreated it and now everything works just fine.

Upvotes: 0

Harshavardhana
Harshavardhana

Reputation: 1428

Alternatively you can take a look at mc tool that i wrote for simplicity, you can download binaries for OS X, Linux and Windows from https://github.com/minio/mc

$ mc share download --expiry=400s <YOUR-S3-URL>

mc also implements '--json' output so you can build a server side nodejs service easily. Without --expiry URL is shared with expiry for default 7days.

$ mc share download --json s3.amazonaws.com/ferenginar/distrikt_2014-01-31T07_31_11-08_00.mp3 | jq . 

{
  "status": "success",
  "url": "https://s3.amazonaws.com/ferenginar/distrikt_2014-01-31T07_31_11-08_00.mp3",
  "share": "https://s3.amazonaws.com/ferenginar/distrikt_2014-01-31T07_31_11-08_00.mp3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI6SNMUFOVIEFOZJA%2F20151125%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20151125T002135Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=082e01d815e6aee8bc567d1d86d79d635b5313337dfba46524f35cfc6858e857",
  "timeLeft": 604800000000000
}

Hope this helps!

Upvotes: 1

Related Questions