A
A
Alexey2017-10-31 12:00:23
JavaScript
Alexey, 2017-10-31 12:00:23

How to download file from S3 Bucket to end user using javascript?

By and large, the task is not trivial.
There is a button with an attached event. When you click on the button, you need to download the file from the S3 Bucket. Actually the file is downloaded using this code:

bucket.getObject(
                    { Bucket: "x_name", Key: s.path + md5(s.user_id.toString()) + '-' + s.user_id + '.' + s.extension },
                    function (error, data) {
                        if (error == null) {
                            window.alert("Loaded " + data.ContentLength + " bytes");
                            // do something with data.Body
                        } 
                    }
                );

And the structure of the resulting file:
59f83cb68b77e101901873.png
I receive the file, but how can I upload it to the browser now? So that, for example, when I receive a file, the user starts downloading?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2017-10-31
@azovl

You can create a link with the attributes target="_blank", download and the path to the file, then call the Click event, instead of the path you can try "data:" + in base64 content to throw

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question