orangewise / s3-zip

Download selected files from an Amazon S3 bucket as a zip file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Saving zip file on client-side that was streamed from server

alexminnaar opened this issue · comments

Hello, sort of a beginner here. I am zipping a few files from S3 on the server side using the Express framework like this

router.get('/download', function (req, res, next) {
    const region = 'us-west-2';
    const bucket = 'my-bucket';
    const folder = 'my-folder/';
    const file1 = '1.jpg';
    const file2 = '2.jpg';
    const file3 = '3.jpg';

    s3Zip
        .archive({ region: region, bucket: bucket}, folder, [file1, file2, file3])
        .pipe(res)
});

and I think that part is working correctly because I am getting a response on the client side that looks like this (from the chrome console)

screen shot 2018-12-05 at 7 59 34 pm

But my goal here is to download the zip file to the client's browser. I am using Angular File Saver to do this. I have tried

var blob = new Blob([res._body], {type: "application/zip"});
FileSaver.saveAs(blob, "test-new.zip");

where res is the response corresponding to the above image. A zip file does download but when I try to open it I get the following error
screen shot 2018-12-05 at 8 05 00 pm

Can anyone see why this is happening?

ah it looks like I just needed to add {responseType: ResponseContentType.Blob } to the request