美文网首页
JW-FastDFS图片服务器

JW-FastDFS图片服务器

作者: Zephyr_07 | 来源:发表于2019-04-11 14:49 被阅读0次

FastDFS是C语言开发的分布式文件系统。提供冗余备份,负载均衡,线性扩容等机制,并注重高可用高性能指标。使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

1.jpg

Client:客户端
Tracker:管理,记录
Storage:同组不同成员存储相同信息,不同组存储不同信息

文件上传:


2.jpg

文件下载:


3.jpg

索引信息示例:group1/M00/02/44/gr4jot534yt43r3543

客户端
下载FastDFS-Java客户端作为工程引用
pom.xml

        <dependency>
            <groupId>org.csource</groupId>
            <artifactId>fastdfs-client-java</artifactId>
            <version>1.27-SNAPSHOT</version>
        </dependency>
配置文件, a.conf:
tracker_server=192.168.25.133:22122

ClientGlobal.init("绝对路径/a.conf");
TrackClient trackClient = new TrackClient();
TrackerServer trackerServer = trackClient.getConnection();
StorageServer StorageServer = null;
StorageClient storageClient = new StorageClient(trackerServer, StorageServer);
//使用storageClient上传文件
String[] result = storageClient.upload_file(...);
// result返回数据库存储路径

FastDFSClient工具类方便使用

//  FastDFSClient
public class FastDFSClient {

    private TrackerClient trackerClient = null;
    private TrackerServer trackerServer = null;
    private StorageServer storageServer = null;
    private StorageClient1 storageClient = null;
    
    public FastDFSClient(String conf) throws Exception {
        if (conf.contains("classpath:")) {
            conf = conf.replace("classpath:", this.getClass().getResource("/").getPath());
        }
        ClientGlobal.init(conf);
        trackerClient = new TrackerClient();
        trackerServer = trackerClient.getConnection();
        storageServer = null;
        storageClient = new StorageClient1(trackerServer, storageServer);
    }
    
    /**
     * 上传文件方法
     * <p>Title: uploadFile</p>
     * <p>Description: </p>
     * @param fileName 文件全路径
     * @param extName 文件扩展名,不包含(.)
     * @param metas 文件扩展信息
     * @return
     * @throws Exception
     */
    public String uploadFile(String fileName, String extName, NameValuePair[] metas) throws Exception {
        String result = storageClient.upload_file1(fileName, extName, metas);
        return result;
    }
    
    public String uploadFile(String fileName) throws Exception {
        return uploadFile(fileName, null, null);
    }
    
    public String uploadFile(String fileName, String extName) throws Exception {
        return uploadFile(fileName, extName, null);
    }
    
    /**
     * 上传文件方法
     * <p>Title: uploadFile</p>
     * <p>Description: </p>
     * @param fileContent 文件的内容,字节数组
     * @param extName 文件扩展名
     * @param metas 文件扩展信息
     * @return
     * @throws Exception
     */
    public String uploadFile(byte[] fileContent, String extName, NameValuePair[] metas) throws Exception {
        
        String result = storageClient.upload_file1(fileContent, extName, metas);
        return result;
    }
    
    public String uploadFile(byte[] fileContent) throws Exception {
        return uploadFile(fileContent, null, null);
    }
    
    public String uploadFile(byte[] fileContent, String extName) throws Exception {
        return uploadFile(fileContent, extName, null);
    }
}

可配合nginx实现文件服务器..

前端可使用KingEdit富文本编辑器插件,富文本编辑器是纯js插件


22.png

common.js中KingEdit文件上传所需参数


1.png

pom添加文件上传组件依赖


2.png

springmvc配置文件上传解析器


3.png

controller配置,使用FastDFS上传


4.png

兼容性问题
使用map加@requestbody作为浏览器返回值,content type为 application/json,部分浏览器KingEditor受影响。
改为使用json字符串作为浏览器返回值,content type则为text/plain。

e.g. 本文仅供个人笔记使用,借鉴部分网上资料。

相关文章

  • JW-FastDFS图片服务器

    FastDFS是C语言开发的分布式文件系统。提供冗余备份,负载均衡,线性扩容等机制,并注重高可用高性能指标。使用F...

  • swoole初探笔记1

    一、建立tcp服务器 图片.png图片.png 二、建立udp服务器 图片.png 三、建立web服务器 四、 w...

  • 网络

    13.服务器图片改了,url没有变,需求,服务器的图片变了,就从服务器加载图片,如果服务器的没变,就从本地加载 1...

  • 图片服务

    搭建一个最简单的图片处理服务器linux中创建图片服务器减轻传统服务器的压力大型网站图片服务器架构的演进 fast...

  • 前端常用的小函数(2)---图片的处理

    需求背景 需要从服务器读取图片到页面(图片大小未知),或者上传图片到服务器(图片体积过大,需要压缩) ,此外后端可...

  • 图片服务器自动优化解密

    图片服务器自动优化解密 图片服务器自动优化解密是在图片URL链接上增加不同特殊参数,服务器自动化生成不同格式、大小...

  • Web

    web图片 图片处理服务器用来处理网站上传的图片满足大小、旋转等要求 图床:将本地图片上传到网络图片服务器,生成网...

  • Flask部署OCR

    情形一:图片在服务器上,传输图片在服务器上的地址 Client: Server: 情形二:图片保存在本地,上传至服...

  • 安卓向django服务器上传图片

    问题描述 服务器端用django编写,能否在android端向服务器传图片?前提是web向django服务器传图片...

  • Android图片转换为Base64编码

    假如服务器需要拿到客户端的图片数据,有两种方法可以实现: 让客户端将图片上传到服务器,将图片的网络URL告诉服务器...

网友评论

      本文标题:JW-FastDFS图片服务器

      本文链接:https://www.haomeiwen.com/subject/khupiqtx.html