压缩图片 图文不能超过20Kb,并上传 that.uploadHead()
compressImage(img) {
var that = this
return new Promise((res) => {
var localPath = plus.io.convertAbsoluteFileSystem(img.replace(‘file://’, ‘’));
console.log(‘after’ + localPath);
// 压缩
plus.io.resolveLocalFileSystemURL(localPath, (entry) => {
entry.file((file) => { // 可通过entry对象操作图片
if (file.size > 20480) { // 压缩后size 大于20Kb
plus.zip.compressImage({
src: img,
quality: 0.5,
}, (event) => {
console.log(‘success zip****’ + event.size);
var fileReader = new plus.io.FileReader(); // 文件系统中的读取文件对象,用于获取文件的内容
fileReader.readAsDataURL(file); //以URL编码格式读取文件数据内容
fileReader.onloadend = function(evt) { //读取文件成功完成的回调函数
console.log(evt.target.result.split(“,”)[1]) //拿到’data:image/jp