How Do I Suspend a Resumable Upload Task?
The API for resumable upload supports the suspension of upload tasks. The code example is as follows:
// 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 uploadCheckpoint;
obsClient.uploadFile({
Bucket : 'bucketname',
Key : 'objectname',
SourceFile : document.getElementById('input-file').files[0],
PartSize : 9 * 1024 * 1024,
ProgressCallback : function(transferredAmount, totalAmount, totalSeconds){
// Obtain the upload progresses.
console.log(transferredAmount * 1.0 / totalSeconds / 1024);
console.log(transferredAmount * 100.0 / totalAmount);
},
ResumeCallback : function(resumeHook, uploadCheckpoint){
// If the upload is suspended after running for three seconds, the API returns an error.
setTimeout(function(){
hook.cancel();
}, 3000);
// Record a breakpoint.
cp = uploadCheckpoint;
}
}, function(err, result){
console.error('Error-->' + err);
// If an error occurs, call the resumable upload API again to continue the upload task.
if(err){
obsClient.uploadFile({
UploadCheckpoint : uploadCheckpoint,
ProgressCallback : function(transferredAmount, totalAmount, totalSeconds){
// Obtain the upload progresses.
console.log(transferredAmount * 1.0 / totalSeconds / 1024);
console.log(transferredAmount * 100.0 / totalAmount);
},
}, function(err, result){
// Reprocess the callback function.
});
}else {
console.log('Status-->' + result.CommonMsg.Status);
console.log('RequestId-->' + result.CommonMsg.RequestId);
}
});
Last Article: How to Improve the Speed of Uploading Large Files over the Public Network?
Next Article: How Can I Obtain the AK and SK?
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.