@PostMapping(value="/file/upload")
@ApiOperation(value = "上传文件")
public Result.Base uploadFile(HttpServletRequest request, MultipartFile file) {
if (file == null){
return Result.ARGUMENT_INVALID;
}
String fileUrl = iFileService.uploadFile(file);
if (StringUtils.isEmpty(fileUrl)){
return Result.UPLOAD_FILE_ERROR;
}
return new Result.Success<>(fileUrl);
}
@Service
public class FileServiceImpl implements IFileService {
private static final Logger logger = LoggerFactory.getLogger(FileServiceImpl.class);
String FileDir = "d:/temp/uploadFile/";
@Override
public String uploadFile(MultipartFile file) {
if (!file.isEmpty()) {
String dataName = file.getOriginalFilename();
try {
byte[] bytes = file.getBytes();
String fileName = FileDir + dataName;
FileOutputStream out = new FileOutputStream(fileName);
out.write(bytes);
out.close();
logger.info("uploadFile : {}",fileName);
return fileName;
} catch (IOException e) {
e.printStackTrace();
}
}
return "";
}
}