2

I am using ng-file-upload to send a file to AWS-S3 in my angular app.

Upload.http({
  url: '/presignedurl',
  headers : {
    'Content-Type': file.type
  },
  data: file
})

It is giving me 403 Forbidden error saying

<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

2 Answers 2

3

AWS S3 needs binary/octet-stream so you can use FileReader class in JavaScript to convert file data to binary/octet-stream

Replace your code with this

var reader = new FileReader();
var xhr = new XMLHttpRequest();

xhr.open("PUT", $scope.url);
reader.onload = function(evt) {
   xhr.send(evt.target.result);
};
reader.readAsArrayBuffer($files[file]);
Sign up to request clarification or add additional context in comments.

1 Comment

This is what i was looking for .Thanks for the answer.
0

You can try something like this

var config = {
    url: result.signed_request,
    headers: {
        "Content-Type": files[0].type != '' files[0].type : 'application/octet-stream'
    },
    method: 'PUT',
    data: files[0]
};
Upload.http(config);

1 Comment

Could you give a minor explanation/insight on how your answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.