Performing an Appendable 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
Appendable upload allows you to upload an object in appendable mode and then append data to the object. You can call ObsClient.appendObject to perform an appendable upload. Sample code is as follows:
// 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'
});
// Create an appendable object. The start position must be 0.
obsClient.appendObject({
Bucket:'bucketname',
Key:'objectname',
Position : 0,
Body : 'Hello OBS'
}).then(function(result){
console.log('Status-->' + result.CommonMsg.Status);
if(result.CommonMsg.Status < 300 && result.InterfaceResult){
console.log('NextPosition-->' + result.InterfaceResult.NextPosition);
}
// Append data to the object.
obsClient.appendObject({
Bucket:'bucketname',
Key:'objectname',
Position : result.InterfaceResult.NextPosition,
Body : 'Hello OBS Again'
}, function(err, result2){
if(err){
console.error('Error-->' + err);
}else{
console.log('Status-->' + result2.CommonMsg.Status);
if(result2.CommonMsg.Status < 300 && result2.InterfaceResult){
console.log('NextPosition-->' + result2.InterfaceResult.NextPosition);
}
}
});
// Use the API for obtaining object properties to get the start position for next appending.
obsClient.getObjectMetadata({
Bucket:'bucketname',
Key:'objectname',
}).then(function(result3){
console.log('Status-->' + result3.CommonMsg.Status);
if(result3.CommonMsg.Status < 300 && result3.InterfaceResult){
console.log('RequestId-->' + result3.InterfaceResult.RequestId);
console.log('NextPosition-->' + result3.InterfaceResult.NextPosition);
}
}).catch(function(err){
console.error('err:' + err);
});
}).catch(function(err){
console.error('err:' + err);
});
- Use the Position parameter to specify the start position for next appending and set it to 0 when you create an appendable object.
- Objects uploaded using ObsClient.putObject, referred to as normal objects, can overwrite objects uploaded using ObsClient.appendObject, referred to as appendable objects. Data cannot be appended to an appendable object anymore once the object has been overwritten by a normal object.
- When you upload an object for the first time in appendable mode, an exception will be thrown (status code 409) if a normal object with the same name exists.
- The ETag returned for an appendable upload is the ETag for the uploaded content, rather than that of the whole object.
- Data size in each appendable upload cannot exceed 5 GB, and 10,000 times of appendable uploads can be performed on a single object.
- After an appendable upload is complete successfully, you can use InterfaceResult.NextPosition obtained from the returned result or call ObsClient.getObjectMetadata, to get the location for next appending.
Last Article: Configuring Lifecycle Management
Next Article: Performing a Multipart Copy
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.