| | |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private EmailService emailService; |
| | | @Value("${upload.type") |
| | | @Value("${upload.type}") |
| | | private String uploadType; |
| | | |
| | | |
| | | public static FtpUtil ftp = null; |
| | | public static AzureBlobUtil azureBlobUtil = null; |
| | | |
| | | @GetMapping("/image/{folder}/{date}/{name}") |
| | | public void getImage(@PathVariable String folder,@PathVariable String date,@PathVariable String name, HttpServletResponse response) throws IOException { |
| | | try { |
| | | initUploadTool(); |
| | | response.setContentType("image/jpeg"); // 根据你的图片类型设置正确的MIME类型 |
| | | log.info("===================图片blob名称"+folder+"/"+date+"/"+name); |
| | | azureBlobUtil.downloadBlobToStream(folder+"/"+date+"/"+name,response.getOutputStream()); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | @ApiOperation(value = "测试企业素材上传下载") |
| | | @RequestMapping(method= RequestMethod.POST,value="/testQwImg") |
| | | @ResponseBody |
| | |
| | | String fileName = folder + fName; |
| | | boolean r1 =false; |
| | | if(StringUtils.equals(Constants.uploadType.blob,uploadType)){ |
| | | r1 = azureBlobUtil.uploadFileWithResponse( fileName,is);//上传 |
| | | r1 = azureBlobUtil.uploadFileWithResponseAndSize( fileName,is,null);//上传 |
| | | }else{ |
| | | r1 = ftp.uploadInputstreamBatch(is, fileName, true,index); |
| | | } |
| | |
| | | @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(MultipartRequest request, HttpServletResponse response, String folder) throws Exception { |
| | | if(Objects.isNull(folder)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | |
| | | String fileName = folder + fName; |
| | | boolean r =false; |
| | | if(StringUtils.equals(Constants.uploadType.blob,uploadType)){ |
| | | r = azureBlobUtil.uploadFileWithResponse( fileName,is);//上传 |
| | | r = azureBlobUtil.uploadFileWithResponseAndSize( fileName,is,null);//上传 |
| | | }else{ |
| | | r = ftp.uploadInputstreamBatch(is, fileName, Constants.equalsInteger(index ,fileList.size()),index); |
| | | } |
| | |
| | | //获得每一个文件 |
| | | String endType = ".jpg"; |
| | | String originname = UUID.randomUUID().toString()+endType; |
| | | InputStream is = QywxUtil.getMediaInputstream(systemDictDataBiz.queryByCode(Constants.QYWX,Constants.QYWX_TOKEN).getCode(),media); |
| | | if(is == null){ |
| | | Map<String,Object> map = QywxUtil.getMediaInputstreamMap(systemDictDataBiz.queryByCode(Constants.QYWX,Constants.QYWX_TOKEN).getCode(),media); |
| | | if(map == null || map.get("data") == null){ |
| | | log.error("企业微信素材下载失败:========="+media); |
| | | continue; |
| | | } |
| | |
| | | String fileName = folder + fName; |
| | | boolean r =false; |
| | | if(StringUtils.equals(Constants.uploadType.blob,uploadType)){ |
| | | r = azureBlobUtil.uploadFileWithResponse( fileName,is);//上传 |
| | | r = azureBlobUtil.uploadFileWithResponseAndSize( fileName, (InputStream) map.get("data"),(Integer)map.get("size"));//上传 |
| | | }else{ |
| | | r = ftp.uploadInputstreamBatch(is, fileName, Constants.equalsInteger(index ,param.getMediaIds().size()),index); |
| | | r = ftp.uploadInputstreamBatch( (InputStream) map.get("data"), fileName, Constants.equalsInteger(index ,param.getMediaIds().size()),index); |
| | | } |
| | | if (r) { |
| | | JSONObject fileJSON = new JSONObject(); |
| | |
| | | String fileName = folder + fName; |
| | | boolean r =false; |
| | | if(StringUtils.equals(Constants.uploadType.blob,uploadType)){ |
| | | r = azureBlobUtil.uploadFileWithResponse( fileName,is);//上传 |
| | | r = azureBlobUtil.uploadFileWithResponseAndSize( fileName,is,null);//上传 |
| | | }else{ |
| | | r = ftp.uploadInputstreamBatch(is, fileName, Constants.equalsInteger(index ,fileList.size()),index); |
| | | } |
| | |
| | | private void initUploadTool() throws Exception{ |
| | | if(StringUtils.equals(Constants.uploadType.blob,uploadType)){ |
| | | if(azureBlobUtil == null){ |
| | | azureBlobUtil = new AzureBlobUtil(systemDictDataBiz.queryByCode(Constants.AZURE_BLOB,Constants.AZURE_BLOB_ACCESSNAME).getCode(), |
| | | azureBlobUtil = new AzureBlobUtil( |
| | | systemDictDataBiz.queryByCode(Constants.AZURE_BLOB,Constants.AZURE_BLOB_ACCESSNAME).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.AZURE_BLOB,Constants.AZURE_BLOB_ACCESSKEY).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.AZURE_BLOB,Constants.AZURE_BLOB_ENDPOINT).getCode(), |
| | | systemDictDataBiz.queryByCode(Constants.AZURE_BLOB,Constants.AZURE_BLOB_CONTAINER).getCode()); |
| | | }else{ |
| | | azureBlobUtil.initClient(); |
| | | } |
| | | }else{ |
| | | if(ftp == null){ |
| | |
| | | String fileName = folder+"/"+fName; |
| | | boolean r =false; |
| | | if(StringUtils.equals(Constants.uploadType.blob,uploadType)){ |
| | | r = azureBlobUtil.uploadFileWithResponse( fileName,is);//上传 |
| | | r = azureBlobUtil.uploadFileWithResponseAndSize( fileName,is,null);//上传 |
| | | }else{ |
| | | r = ftp.uploadInputstream(is,fileName); |
| | | } |