过滤上传文件名;

This commit is contained in:
钱冠学
2024-06-20 14:16:33 +08:00
parent 2bd2578672
commit 00ffd9ee31

View File

@@ -14,11 +14,12 @@ export default class CommonApi {
});
}
static async cosUpload3DCompress(file, quality = 20) {
const _file = await shrinkImage(file, { quality });
const _file = await shrinkImage(file, { quality });
return await this.cosUpload3D(_file);
}
static async cosUpload3D(file, defaultName = "") {
defaultName = defaultName?.replace?.(/[\s+]/g, '_') || ''
const getRandomFileName = () => {
return `3D/upload/${new Date().getTime()}_${Math.floor( Math.random() * 1000 )}`;
};
@@ -37,7 +38,7 @@ export default class CommonApi {
name: `${data.prefix}/${name}`,
file,
};
try {
const location = await createCOS(param);
console.log('888', baseOss, name);
@@ -61,12 +62,14 @@ export default class CommonApi {
* @returns {url:"",name:'fileName'}
*/
static async cosUpload(file, fileName) {
fileName = fileName?.replace?.(/[\s+]/g, '_') || ''
const getRandomFileName = (name) => {
return `survey/${sn.value}/${new Date().getTime()}-${Math.floor(
Math.random() * 1000
)}-${name}`;;
};
const reg = /-|\\|\/|\?|\|\*|\"|\“|\”|\'|\|\|\<|\>|\{|\}|\[|\]|\【|\】|\|\:|\、|\^|\$|\!|\~|\`|\|\\s|\s/g;
const reg = /-|\\|\/|\?|\|\*|\"|\“|\”|\'|\|\|\<|\>|\{|\}|\[|\]|\【|\】|\|\:|\、|\^|\$|\!|\~|\`|\|\\s|\s|\+/g;
const name = fileName ? fileName : getRandomFileName(file?.name?.replace(reg, '') ?? '' ?? `${new Date().getTime()}.png`);
const { data } = await CommonApi.getOssInfo();
const param = {