fdfs往服务器上传文件超时,FastDFS 实现大文件分片上传

1、引入fastdfs

com.github.tobato

fastdfs-client

1.25.2-RELEASE

cn.hutool

hutool-all

4.0.12

2、编写控制层Controller

@GetMapping("/check_before_upload")

@ApiOperation("分片上传前的检测")

public RespMsgBean checkBeforeUpload(@RequestParam("userId") Long userId, @RequestParam("fileMd5") String fileMd5) {

return fileService.checkFile(userId, fileMd5);

}

@PostMapping("/upload_big_file_chunk")

@ApiOperation("分片上传大文件")

public RespMsgBean uploadBigFileChunk(@RequestParam("file") @ApiParam(value="文件",required=true) MultipartFile file,

@RequestParam("userId") @ApiParam(value="用户id",required=true) Long userId,

@RequestParam("fileMd5") @ApiParam(value="文件MD5值",required=true) String fileMd5,

@RequestParam("fileName") @ApiParam(value="文件名称",required=true) String fileName,

@RequestParam("totalChunks") @ApiParam(value="总块数",required=true) Integer totalChunks,

@RequestParam("chunkNumber") @ApiParam(value="当前块数",required=true) Integer chunkNumber,

@RequestParam("currentChunkSize") @ApiParam(value="当前块的大小",required=true) Integer currentChunkSize,

@RequestParam("bizId") @ApiParam(value="业务Id",required=true)String bizId,

@RequestParam("bizCode") @ApiParam(value="业务编码",required=true)String bizCode) {

return fileService.uploadBigFileChunk(file, userId, fileMd5, fileName, totalChunks, chunkNumber, currentChunkSize, bizId, bizCode);

}

3、编写业务接口以及实现类

package com.xxxx.cloud.platfrom.common.file.service.impl;

import cn.hutool.core.convert.Convert;

import cn.hutool.core.io.FileUtil;

import cn.hutool.core.util.StrUtil;

import com.alibaba.fastjson.JSONObject;

import com.xxxx.cloud.platfrom.common.pojo.protocol.RespMsgBean;

import com.github.tobato.fastdfs.domain.StorePath;

import com.github.tobato.fastdfs.service.AppendFileStorageClient;

import com.google.gson.Gson;

import org.apache.commons.lang.StringUtils;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.data.redis.core.RedisTemplate;

import org.springframework.stereotype.Service;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

import javax.imageio.ImageIO;

import javax.servlet.http.HttpServletRequest;

import java.awt.image.BufferedImage;

import java.io.*;

import java.net.URLDecoder;

import java.util.ArrayList;

import java.util.List;

import java.util.Objects;

import java.util.Set;

import java.util.stream.Collectors;

/**

* 〈一句话功能简述〉

* 〈文件接口实现〉

* @author xxxx

* @create 2019/7/1

* @since 1.0.0

*/

@Service

public class FileServiceImpl implements FileService {

private Logger logger = LoggerFactory.g

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
FastDFS中,文件上传连接超时是指上传文件时所建立的连接在指定的时间内未能完成上传操作,导致连接超时错误。根据引用以及引用的内容,可以得出以下结论: 1. 在FastDFS中,通过配置文件fast_dfs.properties可以设置连接超时时长(fdfs.soTimeout)和连接Tracker服务器超时时长(fdfs.connectTimeout)。 2. 当进行上传文件操作时,如果立即提示连接超时错误,可能是由于连接的时间过长导致。而在某些情况下,连接秒超时可能是由于防火墙的限制导致的。引用提到了防火墙可能导致连接秒超时的情况。 综上所述,当使用FastDFS进行文件上传时,如果出现连接超时的情况,可能是由于连接时间过长或防火墙的限制导致的。为了解决该问题,可以适当调整配置文件中的连接超时时长,并确保防火墙没有对连接造成限制。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [FastDFS文件上传实现](https://blog.csdn.net/dengfengan/article/details/126415483)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [上传图片到fastDfs时显示超时](https://blog.csdn.net/weixin_44829930/article/details/108524732)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [fastdfs文件上传下载笔记](https://download.csdn.net/download/qq_37699336/85862208)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值