• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Node.js SDK)
  4. Object Upload
  5. Performing a File-Based Upload

Performing a File-Based Upload

File-based upload uses local files as data sources. The following sample code shows how to perform a file upload:

// Import the OBS library.
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 : 'yourdomainname'
});

obsClient.putObject({
       Bucket : 'bucketname',
       Key : 'objectkey',
       SourceFile : 'localfile'
}, (err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              console.log('Status-->' + result.CommonMsg.Status);
       }
});
NOTE:
  • Use the SourceFile parameter to specify the path to the to-be-uploaded file.
  • The SourceFile parameter and the Body parameter cannot be used together.