H5 uni.uploadFile后台接收不到文件的解决方案

今天遇到一个很奇怪的问题,通过使用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)
                            {
                                
                            }
                            
                        });        
                    })}
原文地址:https://www.cnblogs.com/fogwang/p/14894791.html