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)
                            {
                                
                            }
                            
                        });        
                    })}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM