Search code examples
ibm-cloudobject-storage

file streaming to object store through ibm-cos-sdk


I have seen the sample code in the site https://www.npmjs.com/package/ibm-cos-sdk :

function doCreateObject() {
    console.log('Creating object');
    return cos.putObject({
        Bucket: 'my-bucket',
        Key: 'foo',
        Body: 'bar'
    }).promise();
} 

Is it possible to supply stream as a body (e.g. file being uploaded) instead of supplying the entire body as once?


Solution

  • Try:

    var stream = fs.createReadStream('/Users/paulcarron/Desktop/image.jpeg');
    
    function doCreateObject() {
      console.log('Creating object');
      return cos.putObject({
        Bucket: bucket,
        Key: 'foo.jpg',
        Body: stream
      }).promise();
    }