go-fastdfs安装(国产分布式文件系统)

  1. 开源协议: Unlicense
  2. 官网地址: https://sjqzhang.github.io/go-fastdfs/#vision
  3. 安装:
wget --no-check-certificate  https://github.com/sjqzhang/go-fastdfs/releases/download/v1.3.1/fileserver -O fileserver && chmod +x fileserver && ./fileserver
  1. 上传 文件(基于solon)
@ApiOperation("文件上传")
@Mapping("/upload")
public String upload(UploadedFile file){
    String result = "";
    InputStreamResource isr = new InputStreamResource(file.getContent(),
            file.getName());
    Map<String, Object> params = new HashMap<>();
    params.put("file", isr);
    params.put("path", "86501729");
    params.put("output", "json");
    String resp = HttpUtil.post("http://192.168.1.156:8080/upload", params);
    Console.log("resp: {}", resp);
    result = resp;
    return resp;
}

@ApiOperation("下载")
@Mapping("download")
public void down(Context ctx) throws IOException {
    File file = new File("http://192.168.1.156:8080/group1/zkcy/screenshot-20230217-112719.png");
    ctx.outputAsFile(file);
}
  1. web页面安装

    1. 下载地址: https://github.com/perfree/go-fastdfs-web/releases
    2. 默认端口8088,修改默认端口号更改config/application.yml即可
    3. 如go-fastdfs开启了按组管理,则需要填写组名,反之不用填写
    4. 进入安装页填写集群地址时,该地址需要在go-fastdfs配置文件配置管理ip白名单,否则获取不到数据!
    5. 文件列表功能需要go-fastdfs服务版本在v1.2.8以上
    6. 遇到获取不到信息的功能,先试一下本地调用go-fastdfs接口看是否能获取到
  2. 命令介绍

	1.运行
	./goFastDfsWeb.sh start
	2.查看运行状态
	./goFastDfsWeb.sh status
	3.重新启动
	./goFastDfsWeb.sh restart
	4.停止
	./goFastDfsWeb.sh stop
  1. 如遇到-bash: ./goFastDfsWeb.sh: /bin/bash^M: 坏的解释器: 没有那个文件或目录错误,则执行以下命令再运行

    sed -i 's/\r//' ./goFastDfsWeb.sh
    
  2. web界面配置

    1. 首次运行时,需要填初始化服务信息 在cfg.json中添加白名单如下图
    2. 1. cfg.json 在安装路径下的conf文件夹下
      
    3. 在这里插入图片描述
    4. 初始化时如无分组 请勿填写 仅需填写 ip地址即可 也就是中间的一行
    5. 填写用户名密码即可
    6. 账号信息 zkcy qwer123!
    7. 页面如下 http://192.168.1.156:8088/login
    8. 在这里插入图片描述
  3. 开启上传验证在这里插入图片描述

  4. 在cfg.json中添加 验证url 在这里插入图片描述

  5. 代码示例

    @ApiOperation("文件上传")
    @Mapping("/upload")
    public String upload(UploadedFile file,String authToken){
        InputStreamResource isr = new InputStreamResource(file.getContent(),
                file.getName());
        Map<String, Object> params = new HashMap<>();
        params.put("file", isr);
        params.put("path", "zkcy");
        params.put("output", "json");
        params.put("auth_token", authToken);
        String resp = HttpUtil.post("http://192.168.1.156:8080/upload", params);
        Console.log("resp: {}", resp);
        return resp;
    }
    //cfg.json中配置的验证url 校验token
    @Post
    @ApiOperation("验证")
    @Mapping("/auth")
    public String auth(String auth_token) throws Exception {
        if ("ok".equals(auth_token)){
            return "ok";
        }else {
            return "fail";
        }
    }
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值