zoukankan      html  css  js  c++  java
  • FastDFS 上传,删除文件


    @Component
    public class FastDFSClientWrapper {

    private final Logger logger = LoggerFactory.getLogger(FastDFSClientWrapper.class);

    @Autowired
    private FastFileStorageClient storageClient;

    /**
    * 上传文件
    * @param file 文件对象
    * @return 文件访问地址
    * @throws IOException
    */
    public String uploadFile(MultipartFile file) throws IOException {
    StorePath storePath = storageClient.uploadFile(file.getInputStream(),file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()),null);
    return storePath.getFullPath();
    }

    /**
    * 将一段字符串生成一个文件上传
    * @param content 文件内容
    * @param fileExtension
    * @return
    */
    public String uploadFile(String content, String fileExtension) {
    byte[] buff = content.getBytes(Charset.forName("UTF-8"));
    ByteArrayInputStream stream = new ByteArrayInputStream(buff);
    StorePath storePath = storageClient.uploadFile(stream,buff.length, fileExtension,null);
    return storePath.getFullPath();
    }

    /**
    * 删除文件
    * @param fileUrl 文件访问地址
    * @return
    */
    public void deleteFile(String fileUrl) {
    if (StringUtils.isEmpty(fileUrl)) {
    return;
    }
    try {
    StorePath storePath = StorePath.praseFromUrl(fileUrl);
    storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
    } catch (FdfsUnsupportStorePathException e) {
    logger.warn(e.getMessage());
    }
    }
    }
  • 相关阅读:
    如何根据二叉树 前序遍历 中序遍历 后序遍历 中的两种遍历来反推另一种遍历
    dijkstral改编
    纪念做出来的第一道计算几何题
    链式前向星
    一道简单树形dp
    算法进阶指南—特殊排序
    算法进阶指南二分章节的两道题
    秦皇岛winter camp 总结
    C
    一道cf水题
  • 原文地址:https://www.cnblogs.com/bt2882/p/11424180.html
Copyright © 2011-2022 走看看