之前上传附件都是用插件,或者用form表单体检(这个是很久以前的方式了),今天突发奇想,自己来实现附件上传,具体实现如下

  html:

 <div>
   流程图: <input >提交</button>
</div>

js:

 

    $scope.bpmmainFunction={
            //创建bpm
            createBpm:function(){
                   var file=$("#file")[0].files[0];//获取文件对象
                   var form = new FormData();   //这个是关键
                   form.append("file", file);// 文件对象     
      
                   $.ajax({
                        url:projectName+"/testactivity/test" ,//后台请求
                        type: 'POST',
                        cache: false,
                        data: form,
                        processData: false,
                        contentType: false,
                        async: false
                    }).done(function(res) {
                    
                    }).fail(function(res) {
                        
                    });
        
                
            }
            
    }

 

java 代码:(用的springmvc,MultipartFile 配置就不说了)

    @RequestMapping(value = "test")
    public void test(@RequestParam("file") MultipartFile file2){
        //helloWordService.testProccess();
        //helloWordService.createProccess();
        testBPMService.testProccess(file2);
     
        
    }

如果有多附件 可以通过input file 的change事件来封装上传

$("#file").change(function(){
       
         var  file=this.files[0]//获取附件对象,可通过数组封装再提交
      
        
        
    })

  

相关文章:

  • 2022-12-23
  • 2021-05-16
  • 2021-08-29
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2021-12-03
  • 2022-02-17
  • 2022-12-23
相关资源
相似解决方案