Commit 7cc6d569 by zhoujinghao

上传下载相关代码提交

1 parent 15251a0a
......@@ -30,16 +30,14 @@ public class AttController {
@Autowired
private AttService attService;
/**
*
* @name: uploadToFtp
* @description: 上传文件到ftp
* @params: []
* @return: java.lang.String
* @date: 2019/12/18 15:48
* @auther:
/**上传文件到ftp
*
**/
* @param description 描述
* @param userId 用户id
* @param files 文件
* @return
*/
@ApiOperation( value = "上传文件到ftp",notes = "上传文件到ftp")
@PostMapping(value = "/uploadToFtp",headers = "content-type=multipart/form-data")
@ResponseBody
......@@ -55,13 +53,18 @@ public class AttController {
/**
* 下载ftp上文件到本地
* @return
*@param newFileName 新文件名
*@param fileName 原文件(路径+文件名)
*@param downUrl 下载路径
*@return
*/
@ApiOperation( value = "下载ftp上文件到本地",notes = "下载ftp上文件到本地")
@PostMapping(value = "/downloadFile",headers = "content-type=multipart/form-data")
@ResponseBody
public ApiResponse downloadFile(@RequestParam("files") @Validated MultipartFile[] files) {
ApiResponse apiResponse = attService.downloadFile(files);
public ApiResponse downloadFile(@RequestParam("newFileName") String newFileName,
@RequestParam("fileName") String fileName,
@RequestParam("downUrl") String downUrl) {
ApiResponse apiResponse = attService.downloadFile(newFileName,fileName,downUrl);
return apiResponse;
}
}
......
......@@ -17,7 +17,7 @@ import java.util.List;
*/
public interface AttService {
//下载ftp上文件到本地
ApiResponse downloadFile(MultipartFile[] files);
ApiResponse downloadFile(String newFileName, String fileName, String downUrl);
//上传文件到ftp
ApiResponse uploadToFtp(MultipartFile[] files, String description, Long userId);
......
......@@ -24,9 +24,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.*;
/**
......@@ -53,22 +51,35 @@ public class AttServiceImpl implements AttService {
private AttachmentInfoMapper infoMapper;
/**
* 下载ftp上文件到本地
* @return
*@param newFileName 新文件名
*@param fileName 原文件(路径+文件名)
*@param downUrl 下载路径
*@return
*/
@Override
public ApiResponse downloadFile(MultipartFile[] files) {
// for (MultipartFile file:files) {
// FtpOperationUtils ftpOperationUtils = new FtpOperationUtils();
// try {
// String originalFilename = file.getOriginalFilename();
// InputStream inputStream = ftpOperationUtils.downloadFile(originalFilename);
// FileUtil.writeFromStream(inputStream, "D:\\a1.txt");
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
return null;
public ApiResponse downloadFile(String newFileName, String fileName, String downUrl) {
log.info("下载文件参数newFileName:{}fileName:{}downUrl:",newFileName,fileName,downUrl);
OutputStream os=null;
String lastPath="";
File localFile = new File(downUrl + "/" + newFileName);
if (!localFile.getParentFile().exists()){//文件夹目录不存在创建目录
localFile.getParentFile().mkdirs();
//存放图片的路径地址
StringBuilder sb = new StringBuilder(ftpPath).append("/");
String path = sb.toString();
lastPath=path;
try {
localFile.createNewFile();
os = new FileOutputStream(localFile);
FtpUtil fileFtp = new FtpUtil();
log.info("通过ftp下载文件参数lastPath:{}ileName:{}downUrl:",lastPath,fileName,downUrl);
fileFtp.downloadFile(lastPath,fileName,downUrl);
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return new ApiResponse(ApiResponse.SUCCESS,ApiResponse.SUCCESS_TEXT);
}
/**
......@@ -99,7 +110,7 @@ public class AttServiceImpl implements AttService {
if (!extList.contains(suffixes)) {
return new ApiResponse(ApiResponse.FAIL, MessageEnum.FILE_PICTURE.getRemarks());
}
//图片名称重新命名包括后缀名
//重新命名包括后缀名
String newName = StringUtil.getRandomOrderNumber() + "_" + StringUtil.getRandomOrderNumberString() + suffixes;
// String newName= UUID.randomUUID().toString().replaceAll("\\-", "")+suffixes;
newNameList.add(newName);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!