当前位置: 首页 > news >正文

受欢迎的常州做网站上海网站营销seo电话

受欢迎的常州做网站,上海网站营销seo电话,手机微信网站怎么做,天津建设网网站打不开前言 话说,起初还觉得fastdfs的配置及整合会很简单。。结果不是的。单单篇幅已经有四篇文章了。 正题: 请参考: 关于FastDFS蛋疼的集群和负载均衡(九)之创建FastDFS的Maven项目 这一系列文章有意思。 FastDFS java client SDK 注意。。。…

前言

话说,起初还觉得fastdfs的配置及整合会很简单。。结果不是的。单单篇幅已经有四篇文章了。

正题:
请参考:

关于FastDFS蛋疼的集群和负载均衡(九)之创建FastDFS的Maven项目

这一系列文章有意思。

FastDFS java client SDK

在这里插入图片描述

注意。。。

<dependency><groupId>org.csource</groupId><artifactId>fastdfs-client-java</artifactId><version>1.27-SNAPSHOT</version>
</dependency>

这个是没办法用的,因为,我在gradle上面是broken path,找不到这玩意。。

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

好了,下面这个链接能绑到我们:
FastDFS Client Java » 1.27-RELEASE

<!-- https://mvnrepository.com/artifact/cn.bestwu/fastdfs-client-java -->
<dependency><groupId>cn.bestwu</groupId><artifactId>fastdfs-client-java</artifactId><version>1.27</version>
</dependency>

这是从fork出来的jar拿过来的。

在这里插入图片描述

在这里插入图片描述

起码能用了。

fastDFS与Java整合上传下载

整合过程

1、采用了properties文件作为配置文件

在这里插入图片描述

fastdfs.connect_timeout_in_seconds = 5
fastdfs.network_timeout_in_seconds = 30
fastdfs.charset = UTF-8
fastdfs.http_anti_steal_token = false
fastdfs.http_secret_key = FastDFS1234567890
fastdfs.http_tracker_http_port = 80
#fastdfs.tracker_servers = tw-server:22122,10.0.11.202:22122,10.0.11.203:22122
fastdfs.tracker_servers = tw-server:22122

其他文件:

package net.w2p.DevBase.plugins;import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.URL;
import java.util.Properties;import org.apache.commons.io.FilenameUtils;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;/*** @ClassName FastDFSUtils* @Description FastDFS工具类* @author zhangkai* @date 2017年7月18日*/
public class FastDFSPlugin implements Serializable{/****/private static final long serialVersionUID = -4462272673174266738L;private static TrackerClient trackerClient;private static TrackerServer trackerServer;private static StorageClient1 storageClient1;private static Properties config;static {config=new Properties();InputStream inputStream=null;try{InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/fdfs_client.properties");InputStreamReader is=new InputStreamReader(in,"utf-8");config.load(is);is.close();in.close();}catch (Exception ed){ed.printStackTrace();}try {
//            ClientGlobal.init(resource.getClassLoader().getResource("conf/fdfs_client.conf").getPath());//-_- 没办法,原本的框架是web,app两用的,没办法简单粗暴用一个file path来指定文件路径的。ClientGlobal.initByProperties(config);//trackerclienttrackerClient = new TrackerClient();trackerServer = trackerClient.getConnection();//storageclientstorageClient1 = new StorageClient1(trackerServer,null);} catch (Exception e) {e.printStackTrace();}}/*** fastDFS文件上传* @param file 上传的文件 FastDFSFile* @return String 返回文件的绝对路径*/public static String uploadFile(FastDFSFile file){String path = null;try {//文件扩展名String ext = FilenameUtils.getExtension(file.getName());//mata list是表文件的描述NameValuePair[] mata_list = new NameValuePair[3];mata_list[0] = new NameValuePair("fileName",file.getName());mata_list[1] = new NameValuePair("fileExt",ext);mata_list[2] = new NameValuePair("fileSize",String.valueOf(file.getSize()));path = storageClient1.upload_file1(file.getContent(), ext, mata_list);} catch (Exception e) {e.printStackTrace();}return path;}/*** fastDFS文件下载* @param groupName 组名* @param remoteFileName 文件名* @param specFileName 真实文件名* @return ResponseEntity<byte[]>*/public static ResponseEntity<byte[]> downloadFile(String groupName, String remoteFileName, String specFileName){byte[] content = null;HttpHeaders headers = new HttpHeaders();try {content = storageClient1.download_file(groupName, remoteFileName);headers.setContentDispositionFormData("attachment",  new String(specFileName.getBytes("UTF-8"),"iso-8859-1"));headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);} catch (Exception e) {e.printStackTrace();}return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);}/*** 根据fastDFS返回的path得到文件的组名* @param path fastDFS返回的path* @return*/public static String getGroupFormFilePath(String path){return path.split("/")[0];}/*** 根据fastDFS返回的path得到文件名* @param path fastDFS返回的path* @return*/public static String getFileNameFormFilePath(String path) {return path.substring(path.indexOf("/")+1);}
}
package net.w2p.DevBase.plugins;import java.io.Serializable;
import java.util.Arrays;/*** @ClassName FastDFSFile* @Description FastDFS上传文件业务对象* @author zhangkai* @date 2017年7月18日*/
public class FastDFSFile implements Serializable{private static final long serialVersionUID = 2637755431406080379L;/*** 文件二进制*/private byte[] content;/*** 文件名称*/private String name;/*** 文件长度*/private Long size;public FastDFSFile(){}public FastDFSFile(byte[] content, String name, Long size){this.content = content;this.name = name;this.size = size;}public byte[] getContent() {return content;}public void setContent(byte[] content) {this.content = content;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Long getSize() {return size;}public void setSize(Long size) {this.size = size;}public static long getSerialversionuid() {return serialVersionUID;}
}

测试用文件:

package others;import main.BaseTest;
import net.w2p.DevBase.plugins.FastDFSFile;
import net.w2p.DevBase.plugins.FastDFSPlugin;
import net.w2p.Shared.common.FileReadUtil;
import org.apache.commons.io.FileUtils;
import org.junit.Test;import java.io.*;public class FastDfSTester extends BaseTest {private byte[] toByteArray(InputStream in) throws IOException {ByteArrayOutputStream out = new ByteArrayOutputStream();byte[] buffer = new byte[1024 * 4];int n = 0;while ((n = in.read(buffer)) != -1) {out.write(buffer, 0, n);}return out.toByteArray();}@Testpublic void test_upload(){String encoding = "UTF-8";String fileName="/home/2.jpg";File file = new File(fileName);Long filelength = file.length();byte[] filecontent = new byte[filelength.intValue()];try {FileInputStream in = new FileInputStream(file);byte[] content=toByteArray(in);in.close();FastDFSFile fastDFSFile = new FastDFSFile(content, file.getName(), filelength);String path = FastDFSPlugin.uploadFile(fastDFSFile);System.out.println(path);} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}
}

测试结果:
在这里插入图片描述

在这里插入图片描述

done。

http://www.lbrq.cn/news/2740123.html

相关文章:

  • 网络规划设计师考试资料百度云新手学seo
  • 网页布局有哪些山西seo优化
  • 东莞做网站卓诚营销课程
  • 龙岗做商城网站建设seo推广软件费用
  • 如何优化网站关键词排名平台做推广的技巧
  • 网站平台做推广方案设计国际新闻最新消息今天 新闻
  • 南城网站建设百度爱采购排名
  • 深圳网站建设 卓越创图们网络推广
  • 中企动力中山分公司网站网站制作的流程是什么
  • 济南网站建设服务商北京seo相关
  • 凡客做网站怎么样爱站网seo工具
  • 南昌专业制作网站国内10大搜索引擎
  • php网站案例宁波seo推广哪家好
  • 长沙网站优化联系方式文军seo
  • 广告设计与制作包括哪些网站seo优化服务
  • 企业网站推广的模式网络优化报告
  • 专业制作网站爱战网官网
  • 众鱼深圳网站建设seo公司服务
  • 网页和网站的区别和联系百度的推广方式有哪些
  • 科技公司一般是做什么seo搜索引擎优化方案
  • 给我免费播放片高清在线观看扭曲的家庭恐怖站长工具seo综合查询权重
  • 网站导航栏高度百度推广客户端手机版
  • 衡阳市建设局网站旺道seo推广效果怎么样
  • seo建站推广微信广告朋友圈投放
  • 给网站做优化怎么做智能营销系统开发
  • 衡水高端网站建设上海app网络推广公司
  • web程序员自己做网站seo公司怎样找客户
  • java做网站seo找做网站的公司
  • 产品宣传册设计网站建设google搜索引擎入口google
  • 免费做网站公司天津优化公司哪家好
  • 大模型算法岗面试准备经验分享
  • 《WINDOWS 环境下32位汇编语言程序设计》第2章 准备编程环境
  • 【图论】分层图 / 拆点
  • (论文速读)ViDAR:视觉自动驾驶预训练框架
  • 【机器学习深度学习】OpenCompass:支持的开源评估数据集及使用差异
  • 开发一款多商户电商APP要多久?功能拆解与源码技术落地方案