关键是:FilePart 中获取byte[] public Mono<JsonResult> uploadFile(@RequestPart("file") FilePart filePart,@RequestPart String fileLibraryId, @RequestPart String permissionType,ServerHttpRequest request){ AuthUser authUser= loginService.getCurrentUser(request); if(authUser==null){ return Mono.just(JsonResult.builder().status(-1).message("权限验证失败!").build()); } LOG.info("用户名:{} 用户id:{}",authUser.getFullName(),authUser.getUserId()); String name = filePart.filename(); String extensionName = StringUtils.substringAfterLast(name,"."); JsonResult result=null; final Map<String,byte[]> map=new HashMap(); ByteArrayOutputStream baos=new ByteArrayOutputStream(); try { Flux<DataBuffer> body = filePart.content(); body.subscribe(buffer -> { byte[] bytes = new byte[buffer.readableByteCount()]; buffer.read(bytes); try { baos.write(bytes); } catch (IOException e) { e.printStackTrace(); } DataBufferUtils.release(buffer); //map.put("result", bytes); }); File file = new File(); file.setFile(baos.toByteArray()); file.setName(name); file.setExtName(extensionName); file.setCreateUser(authUser.getFullName()); file.setCreateUserId(authUser.getUserId()); file.setCreateTime(new Date()); file.setFileLibraryId(Long.valueOf(fileLibraryId)); file.setPermissionType(Short.valueOf(permissionType)); file=fileService.uploadFile(file); result=JsonResult.builder().status(1).data(file.getUrl()).build(); }catch (Exception e){ result=JsonResult.builder().status(-1).message(e.getMessage()).build(); } return Mono.just(result); }
webflux fastdfs 文档上传
最新推荐文章于 2024-03-06 22:23:52 发布