|
@@ -1,8 +1,11 @@
|
|
|
package com.fdkankan.web.controller;
|
|
|
|
|
|
+import com.fdkankan.base.constant.LoginConstant;
|
|
|
+import com.fdkankan.common.exception.BaseRuntimeException;
|
|
|
+import com.fdkankan.common.model.ViewResult;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
@@ -15,7 +18,15 @@ public class OpenApiController {
|
|
|
private final String base64Prefix= "data:image/jpg;base64,";
|
|
|
|
|
|
@PostMapping(value = "/getBase64")
|
|
|
- public String getBase64(String fileUrl) throws IOException {
|
|
|
- return base64Prefix.concat(FileUtils.getBase64ContentFromUrl(fileUrl));
|
|
|
+ public ViewResult getBase64(String fileUrl) {
|
|
|
+ if (ObjectUtils.isEmpty(fileUrl)) {
|
|
|
+ throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return ViewResult.success(base64Prefix.concat(FileUtils.getBase64ContentFromUrl(fileUrl)));
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ViewResult.error(e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|