l***@foxmail.com
l***@foxmail.com
  • 发布:2022-05-30 16:39
  • 更新:2023-06-30 10:28
  • 阅读:1026

uni-file-picker ios 真机上传本地图片 报文件格式不正确

分类:uni-app

<uni-file-picker :value="filePathsList" fileMediatype="image" mode="grid" @select="select"
@delete="handleDelete" @progress="progress" @success="success" @fail="fail" :limit="1"
file-extname="png,jpg" />

async select(e) {
console.log('选择文件:', e)
// if()
await this.uploadImg(e.tempFilePaths, 1);
},
// 获取上传进度
progress(e) {
console.log('上传进度:', e)
},

        // 上传成功  
        success(e) {  
            console.log('上传成功')  
        },  

        // 上传失败  
        fail(e) {  
            console.log('上传失败:', e)  
        },  

        handleDelete(err) { // 删除图片  
            const num = this.filePathsList.findIndex(v => v.url === err.tempFilePath);  
            this.filePathsList.splice(num, 1);  
        },  

        async uploadImg(tempFilePaths, token) {  

            // console.log(token)  
            if (!tempFilePaths.length) return;  
            const path = tempFilePaths.pop();  
            this.filePathsList.push({  
                url: path,  
                name: ""  
            })  

            const [err, {  
                data  
            }] = await uni.uploadFile({  
                url: config.uni_app_web_api_url   '/upload',  
                filePath: path,  
                name: 'file',  
                header: {  
                    // "Content-Type": "multipart/form-data",  
                }  
            });  
            // console.log("err", err)  
            // console.log("data", data)  
            let result = JSON.parse(data)  
            // console.log("status", )  
            if (result.status != 'ok') {  
                // upload fail  
                this.filePathsList.pop()  
                uni.showToast({  
                    title: "上传失败",  
                    icon: "none"  
                })  
            } else {  
                // upload success  
                console.log("data", result.data)  
                let img = result.data.split('/')  
                console.log(img)  
                this.filePathsList[this.filePathsList.length - 1].name = config.uni_app_web_api_url    
                    "/public/img/"   img[img.length - 1]  
            }  
            this.uploadImg(tempFilePaths, token);  
        },
2022-05-30 16:39 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

遇到同样问题,请问怎么解决的呀

7***@qq.com

7***@qq.com

同样的问题,怎么解决阿

要回复问题请先登录注册