测试
This commit is contained in:
parent
075b7a58e9
commit
afc851ee65
@ -365,33 +365,33 @@ public class ExpertController {
|
||||
@ApiOperation(value = "上传图片", notes = "仅在上传执业医师资格证使用")
|
||||
@PostMapping("/user/uoloadImg")
|
||||
public ResponseDTO<String> uoloadImg(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
//文件上传只需将参数中的键指定(默认file),值设为文件对象即可,对于使用者来说,文件上传与普通表单提交并无区别
|
||||
// 创建一个临时文件
|
||||
File tempFile = File.createTempFile("temp", file.getOriginalFilename());
|
||||
// 将 MultipartFile 的内容写入到临时文件中
|
||||
try (InputStream inputStream = file.getInputStream();
|
||||
OutputStream outputStream = new FileOutputStream(tempFile)) {
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
params.put("platform", IGANDAN_WX_PLATFORM);
|
||||
params.put("timestamp", System.currentTimeMillis()/1000);
|
||||
String signature = Sha256Util.getSign(params, IGANDAN_WX_token);
|
||||
params.put("signature", signature);
|
||||
params.put("file", tempFile);
|
||||
String result= HttpUtil.post(IGANDAN_WX_HOST + UOLOADIMGV2_URL, params);
|
||||
ResponseDTO responseDTO = JSON.parseObject(result, ResponseDTO.class);
|
||||
if(responseDTO.getCode() == 200){
|
||||
String data = (String) responseDTO.getData();
|
||||
return ResponseDTO.app_ok(IGANDAN_DOC_HOST + data);
|
||||
}
|
||||
}finally {
|
||||
tempFile.deleteOnExit();
|
||||
}
|
||||
// HashMap<String, Object> params = new HashMap<>();
|
||||
// //文件上传只需将参数中的键指定(默认file),值设为文件对象即可,对于使用者来说,文件上传与普通表单提交并无区别
|
||||
// // 创建一个临时文件
|
||||
// File tempFile = File.createTempFile("temp", file.getOriginalFilename());
|
||||
// // 将 MultipartFile 的内容写入到临时文件中
|
||||
// try (InputStream inputStream = file.getInputStream();
|
||||
// OutputStream outputStream = new FileOutputStream(tempFile)) {
|
||||
//
|
||||
// byte[] buffer = new byte[1024];
|
||||
// int bytesRead;
|
||||
// while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
// outputStream.write(buffer, 0, bytesRead);
|
||||
// }
|
||||
// params.put("platform", IGANDAN_WX_PLATFORM);
|
||||
// params.put("timestamp", System.currentTimeMillis()/1000);
|
||||
// String signature = Sha256Util.getSign(params, IGANDAN_WX_token);
|
||||
// params.put("signature", signature);
|
||||
// params.put("file", tempFile);
|
||||
// String result= HttpUtil.post(IGANDAN_WX_HOST + UOLOADIMGV2_URL, params);
|
||||
// ResponseDTO responseDTO = JSON.parseObject(result, ResponseDTO.class);
|
||||
// if(responseDTO.getCode() == 200){
|
||||
// String data = (String) responseDTO.getData();
|
||||
// return ResponseDTO.app_ok(IGANDAN_DOC_HOST + data);
|
||||
// }
|
||||
// }finally {
|
||||
// tempFile.deleteOnExit();
|
||||
// }
|
||||
return ResponseDTO.userErrorParam();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user