修复七牛云上传bug
This commit is contained in:
@@ -74,7 +74,7 @@ export async function uploadToQiniu(file, options = {}) {
|
||||
throw new Error(tokenRes?.msg || '获取上传凭证失败');
|
||||
}
|
||||
|
||||
const { token, keyPrefix, domain } = tokenRes.data;
|
||||
const { token, keyPrefix, domain, region, uploadUrl } = tokenRes.data;
|
||||
|
||||
// 2. 生成文件 key
|
||||
const ext = file.name.split('.').pop();
|
||||
@@ -86,12 +86,15 @@ export async function uploadToQiniu(file, options = {}) {
|
||||
mimeType: file.type || 'application/octet-stream',
|
||||
};
|
||||
|
||||
// 4. 根据区域代码获取七牛云区域对象
|
||||
const qiniuRegion = getQiniuRegion(region);
|
||||
|
||||
const config = {
|
||||
useCdnDomain: true,
|
||||
region: qiniu.region.z0, // 根据实际区域配置
|
||||
region: qiniuRegion,
|
||||
};
|
||||
|
||||
// 4. 创建 observable 对象
|
||||
// 5. 创建 observable 对象
|
||||
const observable = qiniu.upload(file, key, token, putExtra, config);
|
||||
|
||||
// 5. 执行上传
|
||||
@@ -223,3 +226,27 @@ export async function batchUpload(files, options = {}) {
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据区域代码获取七牛云区域对象
|
||||
* @param {string} regionCode 区域代码 (z0, z1, z2, na0, as0, cn-east-2)
|
||||
* @returns {Object} 七牛云区域对象
|
||||
*/
|
||||
function getQiniuRegion(regionCode) {
|
||||
switch (regionCode) {
|
||||
case 'z0':
|
||||
return qiniu.region.z0; // 华东
|
||||
case 'z1':
|
||||
return qiniu.region.z1; // 华北
|
||||
case 'z2':
|
||||
return qiniu.region.z2; // 华南
|
||||
case 'na0':
|
||||
return qiniu.region.na0; // 北美
|
||||
case 'as0':
|
||||
return qiniu.region.as0; // 新加坡
|
||||
case 'cn-east-2':
|
||||
return qiniu.region.cnEast2; // 华东-浙江2
|
||||
default:
|
||||
return qiniu.region.z0; // 默认华东
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user