package com.XX.config.fastdfs;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.ObjectMetadata;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.exception.FdfsUnsupportStorePathException;
import com.github.tobato.fastdfs.proto.storage.DownloadByteArray;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.xx.config.util.CommonCheckUtil;
import com.xx.config.util.CommonUtil;
import com.xx.config.util.DbUtilUuid;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Date;
/**
* @author xx
* @description
* @date 2018/9/28 15:51
**/
@Component
@Slf4j
public class FastDFSClientWrapper {
@Autowired
private FastFileStorageClient storageClient;
@Value("${fdfs.downloadUrl}")
private String fdfsUrl;
/**#1fdfs 2:oss*/
@Value("${file.type}")
private String fileType;
@Autowired
private DbUtilUuid dbUtilUuid;
@Value("${aliyun.oss.accesskeysecret}")
private String accessKeySecret;
@Value("${aliyun.oss.accesskeyid}")
private String accessKeyId;
@Value("${aliyun.oss.endpoint}")
private String endpoint;
@Value("${aliyun.oss.bucketName}")
private String bucketName;
@Value("${aliyun.oss.bucketImgUrl}")
private String bucketImgUrl;
/**oss设置URL过期时间为10年 3600l* 1000*24*365*10**/
private Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000 * 24 * 365 * 20);
/**oss文件存储目录*/
private String filedir = "data/file/";
/**oss图片存储目录*/
private String imagesdir = "data/images/";
/**oss视频存储目录*/
private String videodir = "data/video/";
public OSSClient getOssClient() {
return new OSSClient(endpoint, accessKeyId, accessKeySecret);
}
/**
* 上传文件
* @param file 文件对象
* @return 文件访问地址
* @throws IOException
*/
public String uploadFile(MultipartFile file) {
String path = this.uploadFileNoIp(file);
return fdfsUrl+"/"+path;
}
/**
* 上传文件
* @param inputStream 文件对象
* @param inputStream 文件类型
* @return 文件访问地址
* @throws Exception
*/
public String uploadFileInputStream(InputStream inputStream,String fileType) {
String url = this.uploadFileInputStreamNoIp(inputStream, fileType);
if
文件处理 FastDFS和OSS封装
最新推荐文章于 2024-08-03 16:27:52 发布
本文详细探讨了如何在Java后端环境中对FastDFS和OSS两种文件存储系统进行封装,包括上传、下载、删除等操作的实现,旨在提升文件处理效率和系统集成能力。
摘要由CSDN通过智能技术生成