uni-app中uni.chooseVideo和uni.uploadFile在IOS手机QQ浏览器上传视频后,后端获取文件大小为0

uni-app中uni.chooseVideo和uni.uploadFile在IOS手机QQ浏览器上传视频后,后端获取文件大小为0

项目 内容
产品分类 uniapp/H5
PC开发环境操作系统 Windows
PC开发环境操作系统版本号 win10
HBuilderX类型 正式
HBuilderX版本号 3.3.5
浏览器平台 Chrome
浏览器版本 不知道
项目创建方式 HBuilderX

bug描述:

uni.chooseVideo之后可以正常获取到大小size,宽width,高height和tempFilePath
但是调用uni.uploadFile之后,后端可以正常拿到tempFilePath,但是后端获取到的文件大小是0

此问题只发生在”苹果手机QQ浏览器上传视频“的时候

手机自带浏览器,手机谷歌浏览器都没问题,别的暂时没有试

示例代码:

// 上传视频  
choiceVideos() {  
    console.log(this.uploadType);  
    this.$refs.popup2.close();  
    if (this.uploadType == 2) {  
        return;  
    }  
    this.uploadType = 1;  
    uni.chooseVideo({  
        count: 1,  
        sourceType: ['camera', 'album'],  
        compressed: true,  
        maxDuration: 15,  
        success: res => {  
            console.log(res);  
            // uni.showModal({  
            //  content:"size:"+res.size+"\r\n"+"height:"+res.height+"\r\n"+"width:"+res.width+"\r\n"+res.tempFilePath  
            // });  
            // return  
            this.uploadimg({  
                path: res.tempFilePath,  
            }, 2);  
        },  
        fail: res => {  
            console.log(0);  
            this.uploadType = 0;  
        },  
    });  
},
//多张图片上传  
uploadimg(data, index) {  
    const that = this;  
    let i = data.i ? data.i : 0;  
    let success = data.success ? data.success : 0;  
    let fail = data.fail ? data.fail : 0;  
    var path = '';  
    if (index == 1) {  
        uni.showLoading({  
            title: `正在上传第${success <= 0 ? 1 : success + 1}/${data.path.length}`,  
            mask: true,  
        });  
        path = data.path[i];  
    } else {  
        path = data.path;  
    }  

    // 上传图之前先进行一次压缩  
    uni.uploadFile({  
        url: 'https://xxxxxx/api/common/upload',  
        filePath: path,  
        // name: 'files',  
        name: 'file',  
        header: {  
            TOKEN: uni.getStorageSync('token'),  
        },  
        success: resp => {  
            const tempResult = JSON.parse(resp.data);  
            if (tempResult.code == 1) {  
                success++;  
                uni.showToast({  
                    icon: 'none',  
                    title: `成功${success}张`,  
                });  
                if (index == 1) {  
                    this.$refs.popup.close();  
                    this.imgs.push(tempResult.data.url);  
                } else {  
                    console.log(resp);  
                    this.isVideos = false;  
                    this.videos = tempResult.data.url;  
                    this.cover = `${this.videos}?x-oss-process=video/snapshot,t_0,f_jpg`;  
                }  
            } else {  
                uni.showToast({  
                    icon: 'none',  
                    mask: true,  
                    title: tempResult.msg,  
                });  
            }  
        },  
        fail: err => {  
            this.uploadType = 0;  
            fail++;  
            console.log(`fail:${i}fail:${fail}`);  
        },  
        complete() {  
            if (that.isUploadImg) {  
                i++;  
                if (i == data.path.length) {  
                    // 当图片传完时,停止调用  
                    uni.showToast({  
                        icon: 'none',  
                        title: `成功${success}张`,  
                    });  
                } else {  
                    // 若图片还没有传完,则继续调用函数  
                    data.i = i;  
                    data.success = success;  
                    data.fail = fail;  
                    that.uploadimg(data, that.index); // 递归,回调自己  
                }  
            } else {  
                return;  
            }  
        },  
    });  
    return;  
},

更多关于uni-app中uni.chooseVideo和uni.uploadFile在IOS手机QQ浏览器上传视频后,后端获取文件大小为0的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

是不是上传和接收这边出了问题 导致文件没正确接收下来

更多关于uni-app中uni.chooseVideo和uni.uploadFile在IOS手机QQ浏览器上传视频后,后端获取文件大小为0的实战教程也可以访问 https://www.itying.com/category-93-b0.html


打印过参数,在前端所有参数都获取正常,只有后台在获取的时候,获取不到大小,而且只有苹果手机的qq浏览器会这样,别的全部都正常,包括安卓系统

回到顶部