今天遇到一个很奇怪的问题,通过使用uni.uploadFile上传文件时后端接收不到文件,查过很多资料,原来是自定义了header的Content-Type问题。取消即可,另把自定义文件上传的代码贴出来。

上传文件插件

  <uni-file-picker file-extname="jpg,jpeg,gif,png" @select="selectFile"  ref="files" :auto-upload="false"  limit="1" fileMediatype="image"/>
data() {return {fileInfo:[]}

  select文件动作保存文件信息

methods: {
			selectFile(e){this.fileInfo=e.tempFiles[0];},
......

  

                          uni.uploadFile(
                        {
                            url:"https://www.chinayq.com/api/user/user.ashx",
                            filePath:that.fileInfo.url,
                            name:"file",
                            header: {
                            //"Content-Type": "multipart/form-data", // 不要自定义Content-Type头
                            "token": uni.getStorageSync('token') // token验证
                            },
                            //formData:that.formData,
                            success:function(res)
                            {
                                
                            }
                            
                        });        
                    })}

 

相关文章:

  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-05-16
猜你喜欢
  • 2021-12-14
  • 2021-10-09
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-04-22
  • 2021-11-12
相关资源
相似解决方案