|
@ -7,7 +7,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.yihu.fastdfs.FastDFSUtil;
|
|
|
import com.yihu.jw.base.util.ErrorCodeUtil;
|
|
|
import com.yihu.jw.exception.code.BaseErrorCode;
|
|
|
import com.yihu.jw.file_upload.FileManageService;
|
|
|
import com.yihu.jw.file_upload.FileUploadService;
|
|
|
import com.yihu.jw.restmodel.MutilFileInfo;
|
|
|
import com.yihu.jw.restmodel.iot.common.UploadVO;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
|
|
@ -16,15 +18,18 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.mock.web.MockMultipartFile;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.Base64;
|
|
|
import java.util.Map;
|
|
@ -53,6 +58,8 @@ public class FileUploadController extends EnvelopRestEndpoint {
|
|
|
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
@Autowired
|
|
|
private FileManageService filemanage;
|
|
|
|
|
|
@PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STREAM_IMG)
|
|
|
@ApiOperation(value = "文件流上传图片", notes = "文件流上传图片")
|
|
@ -136,27 +143,45 @@ public class FileUploadController extends EnvelopRestEndpoint {
|
|
|
|
|
|
@PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STREAM)
|
|
|
@ApiOperation(value = "文件流上传文件", notes = "文件流上传文件")
|
|
|
public ObjEnvelop<UploadVO> uploadStream(@ApiParam(value = "文件", required = true)
|
|
|
@RequestParam(value = "file", required = true) MultipartFile file) throws Exception{
|
|
|
public ObjEnvelop<UploadVO> uploadStream(/*@ApiParam(value = "文件", required = true)
|
|
|
@RequestParam(value = "file", required = true) MultipartFile file*/
|
|
|
@ApiParam(value = "jsonData", required = true)
|
|
|
@RequestBody MutilFileInfo param, HttpServletResponse response, HttpServletRequest request) throws Exception{
|
|
|
UploadVO uploadVO = new UploadVO();
|
|
|
if (isClose.equalsIgnoreCase("1")){
|
|
|
Map<String, Object> map = fileUploadService.uploadImg(file);
|
|
|
uploadVO.setFullUri(map.get("accessory").toString());
|
|
|
uploadVO.setFileName(file.getOriginalFilename());
|
|
|
}else if(isClose.equals("2")){
|
|
|
//内网上传
|
|
|
String rs = fileUploadService.request(remote_inner_url,file,null);
|
|
|
logger.info(rs);
|
|
|
JSONObject json = JSON.parseObject(rs);
|
|
|
uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
|
|
|
|
|
|
String taskId ="";
|
|
|
logger.info("上传文件 start...");
|
|
|
try {
|
|
|
taskId=filemanage.chunkUploadByMappedByteBuffer(param);
|
|
|
} catch (IOException e) {
|
|
|
logger.error("文件上传失败。{}", param.toString());
|
|
|
}
|
|
|
if("".equalsIgnoreCase(taskId)){
|
|
|
return success(param.getChunk()+"上传成功",uploadVO);
|
|
|
}else {
|
|
|
// 得到文件的完整名称 xxx.txt
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
InputStream inputStream = file.getInputStream();
|
|
|
uploadVO = fileUploadService.uploadStream(inputStream,originalFilename,fastdfs_file_url);
|
|
|
File pdfFile = new File(taskId);
|
|
|
FileInputStream fileInputStream = new FileInputStream(pdfFile);
|
|
|
MultipartFile file = new MockMultipartFile(pdfFile.getName(), pdfFile.getName(), ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
|
|
|
|
|
if (isClose.equalsIgnoreCase("1")){
|
|
|
Map<String, Object> map = fileUploadService.uploadImg(file);
|
|
|
uploadVO.setFullUri(map.get("accessory").toString());
|
|
|
uploadVO.setFileName(file.getOriginalFilename());
|
|
|
}else if(isClose.equals("2")){
|
|
|
//内网上传
|
|
|
String rs = fileUploadService.request(remote_inner_url,file,null);
|
|
|
logger.info(rs);
|
|
|
JSONObject json = JSON.parseObject(rs);
|
|
|
uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
|
|
|
|
|
|
}else {
|
|
|
// 得到文件的完整名称 xxx.txt
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
InputStream inputStream = file.getInputStream();
|
|
|
uploadVO = fileUploadService.uploadStream(inputStream,originalFilename,fastdfs_file_url);
|
|
|
}
|
|
|
return success("上传成功", uploadVO);
|
|
|
}
|
|
|
return success("上传成功", uploadVO);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|