提交 25df74d1 authored 作者: zyx's avatar zyx

修改一下 矿建

上级 80713a80
......@@ -18,6 +18,11 @@ const client = new OSS({
bucket: 'zws-imgs-pub'
})
// 通过请求头设置限速。
const headers = {
'x-oss-traffic-limit': 8 * 1024 * 100 * 100 // 设置限速,最小100KB/s。设置为 10000KB/s
}
/* 定位到对应 public目录下 */
const DIR_PATH = path.join(__dirname, '../' + conf.DesDir)
/* 上传对应目录 */
......@@ -34,7 +39,10 @@ let fileCount = 1
async function uploadFile (prefixPath, dirFileName) {
try {
const upFilePath = prefixPath.replace(new RegExp(DIR_PATH, 'gi'), '') + path.basename(dirFileName)
let result = await client.put(prefixPath + path.basename(dirFileName), dirFileName)
const result = await client.put(prefixPath + path.basename(dirFileName), dirFileName, {
headers,
timeout: 600000 // 默认超时时长为60000ms。超时直接报错,限速上传时注意修改超时时长。设置为600s
})
if (result.res.status === 200) {
console.log('第' + fileCount++ + '个文件,已上传:' + conf.CDN_BASE + upFilePath)
return { status: 200 }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论