【前端】上传多文件代码

 //上传图片
    upload() {
     var that=this
     uni.chooseImage({
      count: 6, //默认9
      sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
      sourceType: ['album'],     //从相册选择
      success: function(res) {
       that.images=JSON.stringify(res.tempFilePaths);
      that.bimglist=res.tempFilePaths;
      that.bimglist2 = res.tempFilePaths.map((value, index) => {  
                          return {  
                              name: "images",//注意这一行,uni的hello的示例中,这里为key名+index,这样是无法和使用一个固定key名接多个文件的php接口对接上的改为数组下标形式的字符串就解决这个问题了。其效果等同于在html页面上多个同name文件域同时提交表单。  
                              uri: value  
                          }  
                      });  
      }
     });
    },
    //测试
    test(){
     var that=this
     console.log(111111)
     uni.uploadFile({
         url: global_url+'/task/receive', 
         files:that.bimglist2,
       header:{
      // "Content-Type":"multipart/form-data",
         "authenticate":uni.getStorageSync("token").token,
      },
         name: 'images',
         formData: {
            task_style:that.task_style,                              //任务分类:123456789
            task_phone:that.task_phone,                    //任务手机:1:安卓 2:苹果 3:苹果与安卓
            task_title:that.task_title,                     //任务标题
            task_status:that.task_status,                    //任务状态: 1 上架 2下架
            task_time:that.task_time*60,                     //任务时长:秒
            task_single_price:that.task_single_price,              //任务单价
            task_number:that.task_number,                    // 任务总数
            task_link:that.task_link,                   // 任务链接
            task_text:that.task_text,                      // 任务文字验证
            task_remarks:that.task_remarks,                  // 任务备注
         },
         success: (uploadFileRes) => {
             console.log(uploadFileRes);
         }
     });

 

posted @ 2020-09-04 10:28  PythonNew_Mr.Wang  Views(438)  Comments(0Edit  收藏  举报