j***@gmail.com
j***@gmail.com
  • 发布:2023-08-03 10:26
  • 更新:2023-08-03 10:26
  • 阅读:574

想请问一下啊,uni-file-picker选择图片后怎么通过uploadFile上传

分类:uni-app

我所期待的上传(以postman为例,postman测试上传接口可用):

在uni-app使用uni-file-picker和uploadFile如下

<uni-file-picker   
                    v-model="this.upload"    

                    file-mediatype="image"  
                    mode="list"  
                    file-extname="png,jpg"  
                    :limit="1"  
                    @progress="progress"   
                    @success="uploadSuccess"   
                    @fail="uploadFail"   
                    @select="select"  
                />  
            </uni-forms-item>
<script>  
    methods: {  
        select(e) {  
                const tempFilePaths = e.tempFilePaths  
                const img = tempFilePaths[0]  
                // console.log(tempFilePaths)  
                console.log(img)  
                uni.uploadFile({  
                    // TODO  
                    url: urlConfig + "/img/upload",  
                    name: "img",  
                    // filePath: img,  
                    file: img,  
                    header: {  
                        Authorization: store.state.userInfo.authorization,  
                        "Content-Type": "multipart/form-data",  
                    },  
                    success: (res) => {  
                        let data = JSON.parse(res.data)  
                        // console.log(data.data)  
                        this.formData.imgFilename = data.data  
                    }  
                })  
            },  
}  
</script>

页面:

看到的请求过程:

这和想象的完全不一样,后端自然也无法接收,想问一下如何在uploadFile里面拿到图片对象然后上传(我是主要写后端的,可能用图片对象来描述比较符合一点)

2023-08-03 10:26 负责人:无 分享
已邀请:

要回复问题请先登录注册