<template>
<view class="content">
<u-button type="warning" @click="chooseVideo">选视频</u-button>
<u-button type="warning" @click="delVideo">取消</u-button>
</view>
</template>
<script>
import {uploadUrl} from '../../config/env.js';
import {mapGetters} from 'vuex';
export default {
data() {
return {
uploadVideoUrl: uploadUrl + '/uploadapi/video',
};
},
methods: {
delVideo(){
this.uploadVideo = {};
this.uploadPercent = 0;
this.uploadVideoPath = '';
this.uploadTask.offProgressUpdate();
this.uploadTask && this.uploadTask.abort();
this.uploadTask = null;
this.socketTask && this.socketTask.close({
code: 1000
});
this.socketTask = null;
this.heartBeatTimer && clearInterval(this.heartBeatTimer);
this.heartBeatTimer = null;
},
chooseVideo(){
uni.showLoading({
title: '读取视频中'
});
this.uid = this.$u.guid();
uni.chooseVideo({
count: 1,
sourceType: ['camera', 'album'],
compressed: false,
success: (res)=>{
console.log(res);
if(res.size > 524288000){
return uni.showToast({
icon: 'none',
title: '所选的视频超出500M,无法上传!'
})
};
this.uploadPercent = 0;
uni.showLoading({
title: '解析视频中'
});
this.uploadVideoPath = res.tempFilePath;
this.uploadTask = uni.uploadFile({
url: this.uploadVideoUrl,
filePath: res.tempFilePath,
name: 'upfile',
formData: {
uId: this.uid
},
timeout: 7200000,
success: (uploadFileRes) => {
this.uploadVideo = JSON.parse(uploadFileRes.data).data;
uni.showToast({
icon: 'none',
title: '上传成功,可以发布'
});
},
fail: (error)=>{
console.log(error);
if(error.errMsg == 'uploadFile:fail abort'){
uni.showToast({
icon: 'none',
title: '您取消了视频上传!',
duration: 2000
});
}else{
uni.showToast({
icon: 'none',
title: '视频上传失败,请重试!',
duration: 2000
});
};
this.uploadVideo = {};
this.uploadPercent = 0;
this.uploadVideoPath = '';
this.uploadTask && this.uploadTask.abort();
this.uploadTask = null;
this.socketTask && this.socketTask.close({
code: 1000
});
this.socketTask = null;
this.heartBeatTimer && clearInterval(this.heartBeatTimer);
this.heartBeatTimer = null;
},
complete: () => {
this.socketTask && this.socketTask.close({
code: 1000
});
this.socketTask = null;
this.heartBeatTimer && clearInterval(this.heartBeatTimer);
this.heartBeatTimer = null;
this.uploadTask && this.uploadTask.abort();
this.uploadTask = null;
}
});
this.uploadTask.onProgressUpdate((res)=>{
uni.showLoading({
title: '解析进度' + res.progress + '%'
});
if(res.progress >= 100){
uni.hideLoading();
this.uploadTask.offProgressUpdate()
}
})
},
fail: (error) => {
uni.hideLoading();
this.socketTask && this.socketTask.close({
code: 1000
});
this.heartBeatTimer && clearInterval(this.heartBeatTimer);
},
});
},
}
}
</script>
<style lang="scss" scoped>
</style>
用的是uniapp框架,虽然调用接口前缀是uni.但是实测换成wx.uploadFile()仍然是会出现这种情况
多次上传之后就出现内存爆满,微信闪退,真机测试的是华为荣耀v30 系统是鸿OS2.0
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。