使用FastDFS的一套东西DFS+DHT+myfastClient在WEB应用中就可以很好的解决很多的问题,同样的在DHT中的读取配置文件也存在问题的,本想也改一改的,后来转念一想,干脆就把这三哥儿们集成到一块去吧。集成完的项目结构
并没有改太多的核心实现,实在把很多无用的import去掉了,把Test类给去掉了,把读取配置类重新实现了。使用起来就很简单了,提供一个UTIL类的实现代码
/**
*
*
* @ClassName: FastDFSUtil
* @Description: TODO( FastDfs 操作工具类)
* @author LiuYi
* @date 2014年6月5日 下午4:39:19
*
*/
public class FastDFSUtil {
private static final FastDFSUtil fastDFSUtil = new FastDFSUtil();
private static boolean isInit = true;
public static final FastDFSUtil getInstance() {
return fastDFSUtil;
}
static{
try {
PropertiesLoader pl = SpringContextHolder.getBean(PropertiesLoader.class);
DFSCustomIdClient.init(pl.getProperty("dfs"), pl.getProperty("dht"));
} catch (Exception e) {
e.printStackTrace();
}
}
public static DFSCustomIdClient getClient(String fdhtNamespace) {
if(isInit){
getInstance();
isInit = false;
}
try {
return new DFSCustomIdClient(fdhtNamespace);
} catch (MyException e) {
e.printStackTrace();
}
return null;
}
/**
*
* @Description: TODO(上传文件到FastDFS)
* @author LiuYi
* @date 2014年6月5日 下午4:33:39
* @param fileName
* 自定义的文件名
* @param file
* 文件
* @param suffix
* 后缀名
* @return
* @throws IOException
* @throws Exception
* String
*/
public static String upFile(String fileName, File file, String suffix) throws IOException, Exception {
DFSCustomIdClient client = getClient("seafood");
try {
client.uploadFile(fileName, FileUtils.readFileToByteArray(file), suffix);
return fileName + "." + suffix;
} catch (Exception e) {
throw e;
} finally {
client.close();
}
}
/**
*
* @Description: TODO(根据当前年与日生成文件名如
* /2014041806/akdhfajhfdabfdjahfdjafda.png)
* @author LiuYi
* @date 2014年6月5日 下午4:34:55
* @param file
* @param suffix
* @return
* @throws IOException
* @throws Exception
* String
*/
public static String upFile(File file, String suffix) throws IOException, Exception {
DFSCustomIdClient client = getClient("seafood");
try {
Calendar cal = Calendar.getInstance();// 使用日历类
int year = cal.get(Calendar.YEAR);// 得到年
int month = cal.get(Calendar.MONTH) + 1;// 得到月,因为从0开始的,所以要加1
int day = cal.get(Calendar.DAY_OF_MONTH);// 得到天
int hour = cal.get(Calendar.HOUR);// 得到小时
int minute = cal.get(Calendar.MINUTE);// 得到分钟
StringBuffer buffer = new StringBuffer("/").append(year).append(month).append(day).append(hour)
.append(minute).append("/").append(UUID.randomUUID().toString());
client.uploadFile(buffer.toString(), FileUtils.readFileToByteArray(file), suffix);
return buffer.toString() + "." + suffix;
} catch (Exception e) {
throw e;
} finally {
if (client != null)
client.close();
}
}
/**
*
* @Description: TODO(通过DB中的URL 获取到真正的在FastDFS上的URL)
* @author LiuYi
* @date 2014年6月5日 下午5:29:29
* @param dbUrl
* @return String
*/
public static String dbImgUrl2FdfsUrl(String dbUrl){
DFSCustomIdClient client = getClient("seafood");
try {
return client.getFdfsFileId(dbUrl);
} catch (Exception e) {
e.printStackTrace();
}finally{
if(client!=null){
client.close();
}
}
return dbUrl;
}
}
附上源码
- 大小: 7.4 KB
分享到:
相关推荐
stm32f103+dht11温湿度传感器读写例程 stm32f103+dht11温湿度传感器读写例程 stm32f103+dht11温湿度传感器读写例程 stm32f103+dht11温湿度传感器读写例程
LCD+LCD1602+DHT11.zip
OLED+DHT11.zip
本代码是利用51单片机驱动LCD1602显示温湿度数据,数据来源是DHT11模块,可以做到实时监测数据。
仅供参考。解决物联网课程中,对于要求wifi模块esp8266
Arduino uno+esp8266+onenet+dht11温湿度传感器+MQ-2烟雾传感器,onenet云平台查看传感器通过WiFi上传的数据。
bh1750+dht11+yl69+usart hmi+stm32.zip
STM32(c6t6或c8t6)采集温湿度、光照强度后在本地OLED显示 通过8266将采集到的数据上传到onenet云平台进行显示 远程控制led状态+调节led灯的亮度(pwm)
统由Stm32芯片作为核心处理器,Dht11温湿度传感器模块作为检测 传感器,并由Oled显示屏进行显示,最后通过esp8266无线wifi传输到服务器端,服务器端转发到android端进行显示,并能在温度过高时进行震动提醒。...
使用stm32f103连接dht11采集温湿度数据。将收到的数据通过esp8266上传到服务器端
STC15W4K56+DS18B20+DHT11+电机控制温度传感器温湿度监控系统软件源码+说明文档 int main() { uint16_t loop = 0; ///////////////////////////////////////////////// //注意: STC15W4K32S4系列的芯片,上...
基于野火指南者STM32F103VE的DHT11工程文件。本程序是DHT11温湿度传感器数据的读取程序,采用的单片机是STM32F103VET6单片机,提供了DHT11.H头文件,和DHT11.C文件,获取温湿度的函数使用简单,大家可以自行下载
代码对应文章《Nodemcu+DHT11+MicroSD温湿度记录仪(二)》的代码部分,都是一样的。
可以在2.8寸液晶屏上实时显示DHT11温湿度传感器的温度波形和湿度波形,利用了EMWIN中的GRAPH控件
树莓派python3.6写的温度湿度传感器数据采集存储代码,涉及到DHT11湿度BH1750光照度,使用了mysql数据库做存储,Flask控制树莓派开关机操作
这是一个舵机,超声波温湿度 上onenet云的代码 ,不连mpu6050运行不了 屏蔽就好。 基本上一些简单的传感器都可以通用的
利用MSP430g2231+nrf24l01+DHT11实现温湿度远程无线监控