//getFiles.getFilesUrl 是个promise
getFiles.getFilesUrl(path)
.then((files,rejectValue)=>{
if(rejectValue){
console.log('there is some err on getFilesUrl Funciton and the rejectValue is :' + rejectValue);
throw Error();
}
//筛选出文件,防止上传文件夹而导致的错误
let filesPaths = files.filter(file => {
let filePath = path + file;
if(path!='./' || path != '/'){
filePath = path +'/'+ file;
}
let stat = fs.lstatSync(filePath);
if(stat.isFile()) {
return filePath;
}else{
console.log("Warn!!!it isn't a file that can't to be uploaded : " + file)
}
});
filesPaths.map(file => {
var key = prefix + file;
//var localFile = file;
var localFile;
if(path!='./' || path != '/'){
localFile = path +'/'+ file;
}
formUploader.putFile(uploadToken, key, localFile, putExtra, function(respErr,
respBody, respInfo) {
if (respErr) {
throw respErr;
}
if (respInfo.statusCode == 200) {
console.log(respBody);
} else {
console.log("there may be some err with code :" + respInfo.statusCode +'and Info : ' + respBody)
}
});
});
})
.catch(err => {
console.log('meet err:'+err);
});
错误:TypeError: Cannot read property 'forEach' of undefined
在:
.catch(err => {
console.log('meet err:'+err);
});
发出错误
错误原因:zone 是 qiniu对象,而不是字符串