Performing a Streaming Upload

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference

Streaming upload uses stream.Readable as the data source of objects. Sample code is as follows:

Uploading a Network Stream

// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');

// Create an instance of ObsClient.
var obsClient = new ObsClient({
    access_key_id: '*** Provide your Access Key ***',       
    secret_access_key: '*** Provide your Secret Key ***',       
    server : 'https://your-endpoint'
});

var http = require('http');

// Create a network stream.
http.get('http://www.a.com', (res) => {
       obsClient.putObject({
              Bucket : 'bucketname',
              Key : 'objectname',
              Body : res
       }, (err, result) => {
              if(err){
                     console.error('Error-->' + err);
              }else{
                     console.log('Status-->' + result.CommonMsg.Status);
              }
       });
});

Uploading a File Stream

// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');

// Create an instance of ObsClient.
var obsClient = new ObsClient({
    access_key_id: '*** Provide your Access Key ***',       
    secret_access_key: '*** Provide your Secret Key ***',       
    server : 'https://your-endpoint'
});

var fs = require('fs');

obsClient.putObject({
       Bucket : 'bucketname',
       Key : 'objectname',
       // Create a file stream. localfile is the path of the local file to be uploaded. The file name must be specified.
       Body : fs.createReadStream('localfile')
}, (err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              console.log('Status-->' + result.CommonMsg.Status);
       }
});
  • When you use the Body parameter to specify the stream data to be uploaded, the parameter value must be an instance of stream.Readable.
  • To upload a large file, you are advised to use multipart upload.
  • The content to be uploaded cannot exceed 5 GB.