index.js
function(fileName) {
                let file = assets[fileName] || {};
                fileName = basePath + "/" + fileName.replace(/\\/g, '/');
                let key = path.posix.join(uploadPath, fileName);

                return new Promise((resolve, reject) => {
                    let begin = Date.now();
                    cos.putObject(
                        {
                            Bucket: bucket,
                            Region: region,
                            Key: key,
                            Body: fs.createReadStream(file.existsAt),
                            ContentLength: fs.statSync(file.existsAt).size
                        },
                        function(err, body) {
                            uploadedFiles++;
                            spinner.text = tip(uploadedFiles, totalFiles);

                            if (err) return reject(err);
                            body.duration = Date.now() - begin;
                            resolve(body);
                        }
                    );
                });
            }
function(fileName) {
                let file = assets[fileName] || {};
                fileName = basePath + "/" + fileName.replace(/\\/g, '/');
                let key = path.posix.join(uploadPath, fileName);

                return new Promise((resolve, reject) => {
                    let begin = Date.now();
                    cos.putObject(
                        {
                            Bucket: bucket,
                            Region: region,
                            Key: key,
                            Body: fs.createReadStream(file.existsAt),
                            ContentLength: fs.statSync(file.existsAt).size
                        },
                        function(err, body) {
                            uploadedFiles++;
                            spinner.text = tip(uploadedFiles, totalFiles);

                            if (err) return reject(err);
                            body.duration = Date.now() - begin;
                            resolve(body);
                        }
                    );
                });
            }
function ( fileName ) { let file = assets [ fileName ] || { } ; fileName = basePath + "/" + fileName . replace ( / \\ / g , '/' ) ; let key = path . posix . join ( uploadPath , fileName ) ; return new Promise ( ( resolve , reject ) => { let begin = Date . now ( ) ; cos . putObject ( { Bucket : bucket , Region : region , Key : key , Body : fs . createReadStream ( file . existsAt ) , ContentLength : fs . statSync ( file . existsAt ) . size } , function ( err , body ) { uploadedFiles ++ ; spinner . text = tip ( uploadedFiles , totalFiles ) ; if ( err ) return reject ( err ) ; body . duration = Date . now ( ) - begin ; resolve ( body ) ; } ) ; } ) ; }
Perform upload to cos
Perform upload to cos