Commit 42dafa18 authored by liqin's avatar liqin 💬

bug fixed

parent 03e3d5ee
......@@ -4,11 +4,12 @@ import org.apache.commons.io.FilenameUtils;
import org.csource.common.MyException;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import org.springframework.core.io.ClassPathResource;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
/**
* 上传图片到FastDFS
......@@ -17,12 +18,11 @@ public class FastDFSUtils {
static {
try {
ClientGlobal.initByProperties(FastDFSUtils.class.getClassLoader().getResource("fastdfs-client.properties").getPath());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (MyException e) {
Properties props = new Properties();
final InputStream in = new ClassPathResource("fastdfs-client.properties").getInputStream();
props.load(in);
ClientGlobal.initByProperties(props);
} catch (IOException | MyException e) {
e.printStackTrace();
}
}
......
package cn.wisenergy.chnmuseum.party.common.dfs;
import org.apache.commons.io.FilenameUtils;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;
import javax.imageio.ImageIO;
import org.apache.commons.io.FilenameUtils;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
/**
* ueditor
......@@ -24,10 +30,10 @@ public class FastdfsUtil {
private static boolean isInit = false;
private static void init() throws Exception {
String classPath = new File(FastdfsUtil.class.getResource("/").getFile()).getCanonicalPath();
String configFilePath = classPath + File.separator + "fastdfs-client.properties";
logger.info("FastdfsUtils.init加载配置文件:" + configFilePath);
ClientGlobal.initByProperties(configFilePath);
Properties props = new Properties();
final InputStream in = new ClassPathResource("fastdfs-client.properties").getInputStream();
props.load(in);
ClientGlobal.initByProperties(props);
}
private static TrackerClient getTrackerClient() throws Exception {
......@@ -35,9 +41,7 @@ public class FastdfsUtil {
init();
isInit = true;
}
TrackerClient trackerClient = new TrackerClient();
return trackerClient;
return new TrackerClient();
}
private static TrackerServer getTrackerServer() throws Exception {
......@@ -46,12 +50,7 @@ public class FastdfsUtil {
private static StorageClient getStorageClient() throws Exception {
TrackerServer trackerServer = getTrackerServer();
// StorageServer storageServer = null;
// StorageClient storageClient = new StorageClient(trackerServer,
// storageServer);
StorageClient storageClient = new StorageClient(trackerServer, null);
return storageClient;
return new StorageClient(trackerServer, null);
}
/**
......@@ -83,16 +82,14 @@ public class FastdfsUtil {
int height = 0;
if (isImage) {
int[] imageInfo = getImageInfo(fileBuff);
if (imageInfo != null) {
width = imageInfo[0];
height = imageInfo[1];
}
}
NameValuePair[] metaList = new NameValuePair[] { new NameValuePair("fileName", fileName),
NameValuePair[] metaList = new NameValuePair[]{new NameValuePair("fileName", fileName),
new NameValuePair("isImage", isImage + ""), new NameValuePair("mimeType", mimeType),
new NameValuePair("width", width + ""), new NameValuePair("height", height + ""),
new NameValuePair("author", "FastdfsUtils") };
new NameValuePair("author", "FastdfsUtils")};
boolean status = false;
String message = "文件上传失败!";
logger.info("startTIme:" + (new Date().getMinutes()));
......@@ -136,11 +133,11 @@ public class FastdfsUtil {
BufferedImage image = ImageIO.read(in);// 将in作为输入流,读取图片存入image中,而这里in可以为ByteArrayInputStream();
int width = image.getWidth();
int height = image.getHeight();
return new int[] { width, height };
return new int[]{width, height};
} catch (Exception e) {
logger.error("FastdfsUtils.getImageInfo时发生异常:", e);
}
return new int[] { 0, 0 };
return new int[]{0, 0};
}
private static String[] storeFile(byte[] fileBuff, String fileExtName, NameValuePair[] metaList) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment