github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/extensions/s3zip/examples/aws-js/main.js (about)

     1  
     2  var AWS = require('aws-sdk');
     3  
     4  var s3  = new AWS.S3({
     5      accessKeyId: 'YOUR-ACCESSKEYID' ,
     6      secretAccessKey: 'YOUR-SECRETACCESSKEY' ,
     7      endpoint: 'http://127.0.0.1:9000' ,
     8      s3ForcePathStyle: true,
     9      signatureVersion: 'v4'
    10  });
    11  
    12  // List all contents stored in the zip archive
    13  s3.listObjectsV2({Bucket : 'your-bucket', Prefix: 'path/to/file.zip/'}).
    14      on('build', function(req) { req.httpRequest.headers['X-Minio-Extract'] = 'true'; }).
    15      send(function(err, data) {
    16          if (err) {
    17              console.log("Error", err);
    18          } else {
    19              console.log("Success", data);
    20          }
    21      });
    22  
    23  
    24  // Download a file in the archive and store it in /tmp/data.csv
    25  var file = require('fs').createWriteStream('/tmp/data.csv');
    26  s3.getObject({Bucket: 'your-bucket', Key: 'path/to/file.zip/data.csv'}).
    27      on('build', function(req) { req.httpRequest.headers['X-Minio-Extract'] = 'true'; }).
    28      on('httpData', function(chunk) { file.write(chunk); }).
    29      on('httpDone', function() { file.end(); }).
    30      send();
    31