uniapp Blob路径转文件流 并且将json对象和文件流一起传入后台

时间:2021-12-27 05:14:11

//选图片

 chooseImage () {
      uni.chooseImage({
          count: 100, //默认9
          sizeType: [‘original‘, ‘compressed‘],
          success: (res) => {
               console.log(res)
               res.tempFilePaths.forEach(item => {
                   console.log(item)
                   this.imageList.push({
                         src: item,
                         mode: ‘aspectFit‘
                   })
               })
          }
      });
 },
var formData = new FormData();
this.imageList.forEach(item => {
     var myFile = new File([item.src], ‘‘, {type: "multipart/form-data"});
     formData.append(‘file‘, myFile)
})


formData.append(‘json‘, JSON.stringify(this.pub))
axios.post(`http://10.112.61.0:8080/app/productController/createProduct`, formData).then((response) => {
                    
}).then((err) => {
                
})