chooseVideo(mode) {
let that = this
let startTime = '';
uni.chooseMedia({
count: 1,
maxDuration: 30,
mediaType: ["video"],
sourceType: [mode],
success: function(res) {
const videoFile = res.tempFiles[0]
if (videoFile.size > 629145600) {
that.$u.toast('视频大小需要在600M以内');
return
}
if (videoFile.duration > 120) {
that.$u.toast('视频超过2分钟啦,请裁剪后重新上传');
return
}
that.showUpload = true
that.imgNum = 1
that.over = 0
that.videoHeight = videoFile.height
that.videoWidth = videoFile.width
let {
tempFilePath
} = videoFile
let keyName = tempFilePath.split('/')
let times = that.timestamp(true)
const uploadTask = uni.uploadFile({
timeout: 120000,
url: '', //仅为示例,非真实的接口地址
filePath: tempFilePath,
name: 'file',
header: {
'x-oss-tagging': 'oneDayDel=oneDayDel'
},
formData: {
key: times + keyName[keyName.length - 1],
policy: that.ossParams.policy,
OSSAccessKeyId: that.ossParams.accessKeyId,
signature: that.ossParams.signature,
'x-oss-security-token': that.ossParams
.securityToken
},
success: (uploadFileRes) => {
that.over = 1
that.showUpload = false
that.videoFile =``
that.videoImg = videoFile.thumbTempFilePath
that.lastTotalBytesSent = 0;
that.internetSpeed = '0kb/s';
that.progress = 0
},
fail: (err) => {
that.showUpload = false
console.log("会否超时", err.errMsg.indexOf("time"));
if (err.errMsg.indexOf("time") != -1) {
that.$u.toast('上传超时,请选择较小文件或更换网络重试', 3000);
}
that.$wxlog.info('上传相册视频失败==err:', err.errMsg);
that.lastTotalBytesSent = 0;
that.internetSpeed = '0kb/s';
that.progress = 0
}
})
}
});
}
- 发布:2024-05-22 17:10
- 更新:2024-05-22 20:05
- 阅读:43
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 10
HBuilderX类型: 正式
HBuilderX版本号: 4.15
第三方开发者工具版本号: 1.06.2405172win32-x64
基础库版本号: 3.3.5、3.4.3
项目创建方式: HBuilderX
示例代码:
操作步骤:
- 调用uni.chooseMedia选择视频
- 调用uni.uploadFile上传到oss服务器
- 调用uni.chooseMedia选择视频
- 调用uni.uploadFile上传到oss服务器
预期结果:
正常上传到oss服务器
正常上传到oss服务器
实际结果:
个别客户手机会出现网络超时或者自动取消上传
个别客户手机会出现网络超时或者自动取消上传
bug描述:
个别手机会出现以下问题
问题一:上传缓慢导致网络超时
问题二:视频上传到30%突然就停止了