IBM / ibm-cos-sdk-js

ibm-cos-sdk-js
Apache License 2.0
38 stars 19 forks source link

Downloading files from a bucket #27

Closed justin-chen closed 6 years ago

justin-chen commented 6 years ago

Is it possible to download files from buckets? In python, you're able to use download_file() (https://ibm.github.io/ibm-cos-sdk-python/reference/services/s3.html#S3.Bucket.download_file), but it seems this is missing in JS.

runnerpaul commented 6 years ago

@justin-chen I'm looking into this now.

paul-carron commented 6 years ago

@justin-chen JS doesn't have download_file(). I'd suggest you use createWriteStream with getObject(). A simple example of this can be found below:

var params = { Bucket: ‘my-bucket-pc’, Key: ‘foo’ }; var file = fs.createWriteStream(‘/Users/me/Downloads/foo’); function doGetObject() { console.log(‘Getting object’); cos.getObject(params).createReadStream().pipe(file); }

paul-carron commented 6 years ago

@justin-chen, did my last reponse resolve your issue?