依赖
org.springframework
spring-mock
2.0.8
com.alibaba
fastjson
1.2.62
service实现
public RestResponseBody<EnginePublishUnpackResVo> unpack(EnginePublishUnpackVo vo) {
String name = "Local" + "_" + aiEnginePublish1.getEngineVersion() + "_" + (int) ((Math.random() * 9 + 1) * 10000) + ".json";
File file = new File("src\\main\\resources\\" + name);
try {
Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
String userData = JSON.toJSONString(resVo);
writer.write(userData);
writer.flush();
writer.close();
FileInputStream input = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile("file", file.getName() + ".json", "multipart/form-data", IOUtils.toByteArray(input));
BosUploadResponseDTO dto = msFileUploadFeign.bosFileUpload(name, "xxx", multipartFile).getData();
input.close();
} catch (Exception e) {
log.error("upload file error : {}", String.valueOf(e));
}
boolean del = file.delete();
log.info("file delete: {}", del);
return RestResponseBody.success(resVo);
}