LOGO

JS wangedit3实现图片压缩


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {compressAccurately} from "image-conversion";
import {ediotImgUpload} from "@/api/upload"

editorConfig.MENU_CONF['uploadImage'] = {
// 自定义上传
async customUpload(resultFiles, insertImgFn) {
if (resultFiles.size / 1024 > 200) { // 大于 200 kb 就压缩
compressAccurately(resultFiles, 200).then(res => {
let formData = new FormData();
formData.append('file', res);
ediotImgUpload(formData).then(data=>{
if(data.code === 200){
insertImgFn(import.meta.env.VITE_APP_BASE_URL + data.fileName)
}
})
})
}else{
let formData = new FormData();
formData.append('file', resultFiles);
ediotImgUpload(formData).then(data=>{
if(data.code === 200){
insertImgFn(import.meta.env.VITE_APP_BASE_URL + data.fileName)
}
})
}
}
}

文章作者: 68HTML
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 68HTML !
  目录