1

On my express server I have a post-request which is getting a pdf file from Amazon S3 and sending it back to angular. This is how my express server endpoint ends with:

var fileStream = s3.getObject(options).createReadStream();
fileStream.pipe(res);

On the angular side of things I am posting and trying to save this

$http.post(url, data)
.then(function (data, status, headers, config) {
  var file = new Blob([data.data], {type: 'application/pdf'});
  FileSaver.saveAs(file, vm.projectName);
})

I get a pdf file which is not valid. I has about 300kb (more than original file) and I believe its not pdf but a buffer?

What I am trying to achieve: - Post Request to server - Server gets file from S3, Sends it back to Angular Controller - Angular Controller saves it as .png

1 Answer 1

1

When you're making POST call, set responseType of request to arrayBuffer inside configuration, so that response will get transformed to correctly.

$http.post(url, data, {responseType: "arraybuffer"})
Sign up to request clarification or add additional context in comments.

1 Comment

Thank your sir! Exactly what I needed

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.