promise 创建和使用
Create Promise on the fly...
let getChuckNorrisFact = new Promise((resolve, reject) => {
cos.putObject(
{
Bucket: "htsha-1257254264",
Region: "ap-shanghai",
Key: item.file.name,
//StorageClass: 'STANDARD',
Body: item.file, // 上传文件对象
onProgress: function(progressData) {
//console.log(JSON.stringify(progressData));
}
},
function(err, data) {
if (err) reject(err);
else resolve(data || "");
}
);
});
var consumePromise = function() {
getChuckNorrisFact
.then(function(fulfilled) {
// yay, you got a new phone
console.log(fulfilled);
// output: { brand: 'Samsung', color: 'black' }
})
.catch(function(error) {
// oops, mom don't buy it
console.log(error);
// output: 'mom is not happy'
});
};
consumePromise();