1
zj
2025-09-22 095f37ff949a43fe51fdf90a7a5acb2fe508f205
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.nq.service.impl;
 
import com.google.common.collect.Lists;
import com.nq.common.ServerResponse;
import com.nq.service.IFileUploadService;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
 
import com.nq.utils.PropertiesUtil;
import com.nq.utils.ftp.FTPUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
 
@Service("iFileUploadService")
 
public class FileUploadServiceImpl
 
        implements IFileUploadService {
 
    private static final Logger log = LoggerFactory.getLogger(FileUploadServiceImpl.class);
 
 
    public ServerResponse upload(MultipartFile file, String path) {
        String fileName = file.getOriginalFilename();
        String fileExtentionName = fileName.substring(fileName.lastIndexOf(".") + 1);
        String uploadFileName = UUID.randomUUID() + "." + fileExtentionName;
        File tartgetFile = new File(PropertiesUtil.getProperty("ftp.address"), uploadFileName);
        try {
            file.transferTo(tartgetFile);
            return ServerResponse.createBySuccess(tartgetFile.getName());
        } catch (IOException e) {
            return ServerResponse.createByErrorMsg("上传失败");
        }
 
 
    }
 
}