refactor: 添加获取文件byte[]接口
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package org.agt.module.infra.api.file;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.agt.framework.common.pojo.CommonResult;
|
||||
import org.agt.module.infra.api.file.dto.FileCreateReqDTO;
|
||||
import org.agt.module.infra.service.file.FileService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -14,6 +17,7 @@ import static org.agt.framework.common.pojo.CommonResult.success;
|
||||
@Validated
|
||||
public class FileApiImpl implements FileApi {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FileApiImpl.class);
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
@@ -23,4 +27,17 @@ public class FileApiImpl implements FileApi {
|
||||
createReqDTO.getDirectory(), createReqDTO.getType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<byte[]> getFileContent(String url) {
|
||||
byte[] content = null;
|
||||
try {
|
||||
String path = StrUtil.subAfter(url, "/get/", false);
|
||||
String configId = StrUtil.subBetween(url, "/file/", "/get/");
|
||||
content = fileService.getFileContent(Long.valueOf(configId), path);
|
||||
} catch (Exception e) {
|
||||
log.error("get file content error {}", url, e);
|
||||
}
|
||||
return success(content);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user