| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import org.springframework.web.multipart.MultipartRequest; |
| | | import org.springframework.web.multipart.commons.CommonsMultipartResolver; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | @ApiOperation(value = "批量上传文件到FTP") |
| | | @RequestMapping(method= RequestMethod.POST,value="/uploadBatch") |
| | | @ResponseBody |
| | | public void uploadBatch(@RequestParam("files") MultipartFile[] fileList,HttpServletRequest request, HttpServletResponse response, String folder) throws Exception { |
| | | // public void uploadBatch(@RequestParam("files") MultipartFile[] fileList,HttpServletRequest request, HttpServletResponse response, String folder) throws Exception { |
| | | public void uploadBatch(MultipartRequest request, HttpServletResponse response, String folder) throws Exception { |
| | | if(Objects.isNull(folder)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Set<String> setList = request.getMultiFileMap().keySet(); |
| | | if(Objects.isNull(setList)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | List<MultipartFile> fileList = new ArrayList<>(); |
| | | for(String str:setList){ |
| | | List<MultipartFile> fl = request.getMultiFileMap().get(str); |
| | | fileList.addAll(fl); |
| | | } |
| | | if(Objects.isNull(fileList)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | |
| | | context.put("success", true); |
| | | context.put("code", 200); |
| | | context.put("errno",0); |
| | | JSONArray jsonArray = new JSONArray(); |
| | | if (fileList.length > 0) { |
| | | JSONArray jsonArray = new JSONArray(); |
| | | if (fileList.size() > 0) { |
| | | //遍历文件列表 |
| | | Integer index = Constants.ONE; |
| | | for (MultipartFile file :fileList) { |
| | |
| | | if(StringUtils.equals(Constants.uploadType.blob,uploadType)){ |
| | | r = azureBlobUtil.uploadFileWithResponse( fileName,is);//上传 |
| | | }else{ |
| | | r = ftp.uploadInputstreamBatch(is, fileName, Constants.equalsInteger(index ,fileList.length),index); |
| | | r = ftp.uploadInputstreamBatch(is, fileName, Constants.equalsInteger(index ,fileList.size()),index); |
| | | } |
| | | if (r) { |
| | | JSONObject fileJSON = new JSONObject(); |