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

feature: 测试upload

parent 9ef35f48
...@@ -178,34 +178,37 @@ module.exports = { ...@@ -178,34 +178,37 @@ module.exports = {
SecretId: 'AKIDVlxtVqOK9i0wc0m0e7C5saATZnl2xvUx', SecretId: 'AKIDVlxtVqOK9i0wc0m0e7C5saATZnl2xvUx',
SecretKey: 'NWQ3VlmWeFtIQHrDI6F9oCheMq41lGVV' SecretKey: 'NWQ3VlmWeFtIQHrDI6F9oCheMq41lGVV'
}); });
const filesList = []; const filesPath = [];
function isValid (path) { function isValid (path) {
const format = ['.ico', '.html', '.ttf', '.woff', '.woff2']; const format = ['.ico', '.html', '.ttf', '.woff', '.woff2'];
return !format.some(v => path.endsWith(v)) return !format.some(v => path.endsWith(v))
} }
function readFileList(dir, filesList = []) { function readFileList(dir, filesPath = []) {
  const files = fs.readdirSync(dir);   const files = fs.readdirSync(dir);
  files.forEach((item, index) => {   files.forEach((item, index) => {
    var fullPath = path.join(dir, item);     var fullPath = path.join(dir, item);
    const stat = fs.statSync(fullPath);     const stat = fs.statSync(fullPath);
    if (stat.isDirectory()) {       if (stat.isDirectory()) {  
      readFileList(path.join(dir, item), filesList); //递归读取文件       readFileList(path.join(dir, item), filesPath); //递归读取文件
    } else if(isValid(fullPath)) {            } else if(isValid(fullPath)) {       
      filesList.push(fullPath);                 filesPath.push(fullPath);          
    }        }   
  });   });
  return filesList;   return filesPath;
} }
readFileList(path.resolve(__dirname, './public'), filesList); readFileList(path.resolve(__dirname, './public'), filesPath);
// console.log('filepath', filesList); const filesList = filesPath.map(filepath => {
const files = [{ const filesPathArr = filepath.split('/');
Bucket: 'misc-1258270469', const Key = `qb/${filesPathArr[filesPathArr.length - 1]}`;
Region: 'ap-beijing', return {
Key: 'qb/fixIosTitle.html', Bucket: 'misc-1258270469',
FilePath: filepath, Region: 'ap-beijing',
}]; Key,
FilePath: filepath
}
});
cos.uploadFiles({ cos.uploadFiles({
files: files, files: filesList,
SliceSize: 1024 * 1024, SliceSize: 1024 * 1024,
onProgress: function (info) { onProgress: function (info) {
var percent = parseInt(info.percent * 10000) / 100; 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