Commit 41d252c3 authored by 郝聪敏's avatar 郝聪敏

feature: 测试upload

parent 9ef35f48
......@@ -178,34 +178,37 @@ module.exports = {
SecretId: 'AKIDVlxtVqOK9i0wc0m0e7C5saATZnl2xvUx',
SecretKey: 'NWQ3VlmWeFtIQHrDI6F9oCheMq41lGVV'
});
const filesList = [];
const filesPath = [];
function isValid (path) {
const format = ['.ico', '.html', '.ttf', '.woff', '.woff2'];
return !format.some(v => path.endsWith(v))
}
function readFileList(dir, filesList = []) {
function readFileList(dir, filesPath = []) {
  const files = fs.readdirSync(dir);
  files.forEach((item, index) => {
    var fullPath = path.join(dir, item);
    const stat = fs.statSync(fullPath);
    if (stat.isDirectory()) {  
      readFileList(path.join(dir, item), filesList); //递归读取文件
      readFileList(path.join(dir, item), filesPath); //递归读取文件
    } else if(isValid(fullPath)) {       
      filesList.push(fullPath);          
      filesPath.push(fullPath);          
    }   
  });
  return filesList;
  return filesPath;
}
readFileList(path.resolve(__dirname, './public'), filesList);
// console.log('filepath', filesList);
const files = [{
readFileList(path.resolve(__dirname, './public'), filesPath);
const filesList = filesPath.map(filepath => {
const filesPathArr = filepath.split('/');
const Key = `qb/${filesPathArr[filesPathArr.length - 1]}`;
return {
Bucket: 'misc-1258270469',
Region: 'ap-beijing',
Key: 'qb/fixIosTitle.html',
FilePath: filepath,
}];
Key,
FilePath: filepath
}
});
cos.uploadFiles({
files: files,
files: filesList,
SliceSize: 1024 * 1024,
onProgress: function (info) {
var percent = parseInt(info.percent * 10000) / 100;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment