Skip to content

Commit

Permalink
chore: 代码格式化
Browse files Browse the repository at this point in the history
  • Loading branch information
limaofeng committed Sep 16, 2021
1 parent 5fdca75 commit dda3f44
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
import org.jfantasy.storage.FileObject;
import org.springframework.beans.factory.annotation.Value;

/** @author: fengmeng @Date: 2019/5/7 20:45 */
/**
* 文件对象格式指令
*
* @author fengmeng
* @date 2019/5/7 20:45
*/
@Slf4j
public class FileObjectFormatDirective implements SchemaDirectiveWiring {

Expand Down Expand Up @@ -66,15 +71,14 @@ private String buildFileObject(FileObject fileObject, String type) {

/** 通过FileObject获取图片base64位编码 */
public static String getImageBase64ByFileObject(FileObject fileObject, String url) {
String base64;
if (fileObject.getLength() > (1024 * 1014 * 5L)) {
return null;
}
if (!"image".equals(fileObject.getMimeType().substring(0, 5))) {
return null;
}
try {
return "data:" + fileObject.getMimeType() + ";base64," + ImageToBase64ByOnline(url);
return "data:" + fileObject.getMimeType() + ";base64," + imageToBase64ByOnline(url);
} catch (IOException e) {
log.error(e.getMessage());
return null;
Expand All @@ -84,23 +88,23 @@ public static String getImageBase64ByFileObject(FileObject fileObject, String ur
/**
* 在线图片转换成base64字符串
*
* @param imgURL 图片线上路径
* @param imgUrl 图片线上路径
* @author ZHANGJL
* @date 2018-02-23 14:43:18
* @return String
*/
public static String ImageToBase64ByOnline(String imgURL) throws IOException {
public static String imageToBase64ByOnline(String imgUrl) throws IOException {
ByteArrayOutputStream data = new ByteArrayOutputStream();
// 创建URL
URL url = new URL(imgURL);
URL url = new URL(imgUrl);
byte[] by = new byte[1024];
// 创建链接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
InputStream is = conn.getInputStream();
// 将内容读取内存中
int len = -1;
int len;
while ((len = is.read(by)) != -1) {
data.write(by, 0, len);
}
Expand Down

0 comments on commit dda3f44

Please sign in to comment.