java将文件流传给前端,JAVA基础知识之InputStreamReader流 和 将本地文件通过前端上传到服务器上...

将本地文件通过前端上传到服务器上

public BaseResponseSwagger resolveFile(@Valid @ApiParam(value = "file")@RequestParam(name = "file",required = true) MultipartFile file){

if(file.isEmpty()){

throw new SoftwareException(ComStatusCodeEnum.COM_PARAM_VALID_ERROR,"文件为空");

}

String path=SoftwareConfig.ZIP_PATH;

File dir = new File(path);

if(!dir.exists()){

dir.mkdirs();

}

UUID id = UUID.randomUUID();

String fileName = file.getOriginalFilename();

String zipName = id+fileName.substring(fileName.lastIndexOf("."));

try {

FileOutputStream zipOut = new FileOutputStream(new File(dir,zipName));

zipOut.write(file.getBytes());

zipOut.close();

}catch (Exception e){

throw new SoftwareException(ComStatusCo

你可能感兴趣的:(java将文件流传给前端)