Commit 5609dca6 by 牟邦恺

add cloudera repo

parent 6bcff9f5
package com.hikcreate.service.fdfs.service;
/**
* @author 赵东
* @create 2019/3/22 13:39
*/
public interface FileService {
/**
* 上传文件
* @param file
* @param fileName
* @return
*/
String uploadFile(byte[] file, String fileName);
/**
* 下载文件
*
* @param path 文件路径
* @return 字节数组
*/
byte[] downloadFile(String path);
}
package com.hikcreate.service.fdfs.service.impl;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.domain.upload.FastImageFile;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.hikcreate.service.fdfs.FastDFSClient;
import com.hikcreate.service.fdfs.service.FileService;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
/**
* @author 赵东
* @create 2019/3/22 13:45
*/
@Service
public class FileServiceImpl implements FileService {
@Resource
private FastDFSClient fastDFSClient;
@Autowired
private FastFileStorageClient storageClient;
@Override
public String uploadFile(byte[] file, String fileName) {
try {
//将文件上装到fast文件服务器上,成功则返回文件保存的路径
String path = fastDFSClient.uploadFile(file, fileName);
if (!StringUtils.hasText(path)) {
// log.error("Upload Img Error");
}
// log.info("Upload Img Success. path {}", ("/group" + path.split("group")[1]));
return "/group" + path.split("group")[1];
} catch (Exception e) {
// log.error("Upload Img Error, msg ={}", e);
// throw new BusinessException("上传图片失败");
}
}
@Override
public byte[] downloadFile(String path) {
return fastDFSClient.download(path);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment