|
|
|
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.List; |
|
|
|
@@ -45,7 +46,7 @@ public class UploadController extends BaseController { |
|
|
|
@PostMapping(value = "/awsFileUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
|
@ApiOperation("上传文件") |
|
|
|
@SystemControllerLog(description = "文件上传") |
|
|
|
public ResultData awsfileUpload(@RequestParam("file") MultipartFile multiReq) throws Exception{ |
|
|
|
public ResultData awsfileUpload(@RequestParam("file") MultipartFile multiReq) throws Exception { |
|
|
|
logger.info("[" + getIpAddr() + "] UploadController::awsfileUpload"); |
|
|
|
|
|
|
|
ObjectMetadata metadata = new ObjectMetadata(); |
|
|
|
@@ -66,7 +67,6 @@ public class UploadController extends BaseController { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 图片上传 |
|
|
|
* |
|
|
|
@@ -77,7 +77,7 @@ public class UploadController extends BaseController { |
|
|
|
@PostMapping(value = "/awsImgUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
|
@ApiOperation("上传图片") |
|
|
|
@SystemControllerLog(description = "上传图片") |
|
|
|
public ResultData awsImgUpload(@RequestParam("file") MultipartFile multiReq) throws Exception{ |
|
|
|
public ResultData awsImgUpload(@RequestParam("file") MultipartFile multiReq) { |
|
|
|
logger.info("[" + getIpAddr() + "] UploadController::awsImgUpload"); |
|
|
|
long size = multiReq.getSize(); |
|
|
|
final long length = 2097152; |
|
|
|
@@ -85,7 +85,7 @@ public class UploadController extends BaseController { |
|
|
|
return new ResultData(ErrorCode.PICTURE_SIZE_EXCEED); |
|
|
|
} |
|
|
|
String fileName = UUID.randomUUID().toString(); |
|
|
|
String tempFileName = fileName; |
|
|
|
String tempFileName = fileName; |
|
|
|
String fileFormat = ""; |
|
|
|
|
|
|
|
int dot = multiReq.getOriginalFilename().lastIndexOf('.'); |
|
|
|
@@ -98,40 +98,45 @@ public class UploadController extends BaseController { |
|
|
|
|
|
|
|
System.out.println(fileName); |
|
|
|
|
|
|
|
FileOutputStream fos = null; |
|
|
|
String imgFormat = ImgUtil.getImgFormat(fileFormat); |
|
|
|
if(StringUtils.isNotBlank(imgFormat)) { |
|
|
|
String localImgFileName = fmUploadDir + tempFileName + "-1" + fileFormat; |
|
|
|
String localNewImgFileName = fmUploadDir + tempFileName + fileFormat; |
|
|
|
BufferedInputStream fs = null; |
|
|
|
File localFile = new File(localImgFileName); |
|
|
|
fos = new FileOutputStream(localFile); |
|
|
|
fs = (BufferedInputStream) multiReq.getInputStream(); |
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
int len = 0; |
|
|
|
while ((len = fs.read(buffer)) != -1) { |
|
|
|
fos.write(buffer, 0, len); |
|
|
|
try { |
|
|
|
FileOutputStream fos = null; |
|
|
|
String imgFormat = ImgUtil.getImgFormat(fileFormat); |
|
|
|
if (StringUtils.isNotBlank(imgFormat)) { |
|
|
|
String localImgFileName = fmUploadDir + tempFileName + "-1" + fileFormat; |
|
|
|
String localNewImgFileName = fmUploadDir + tempFileName + fileFormat; |
|
|
|
BufferedInputStream fs = null; |
|
|
|
File localFile = new File(localImgFileName); |
|
|
|
fos = new FileOutputStream(localFile); |
|
|
|
fs = (BufferedInputStream) multiReq.getInputStream(); |
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
int len = 0; |
|
|
|
while ((len = fs.read(buffer)) != -1) { |
|
|
|
fos.write(buffer, 0, len); |
|
|
|
} |
|
|
|
fos.close(); |
|
|
|
fs.close(); |
|
|
|
logger.info("local file: " + localImgFileName); |
|
|
|
File newFile = ImgUtil.thinImage(localImgFileName, localNewImgFileName, imgFormat); |
|
|
|
logger.info("local new file: " + localNewImgFileName); |
|
|
|
// 删除本地缓存 |
|
|
|
localFile.delete(); |
|
|
|
ObjectMetadata metadata = new ObjectMetadata(); |
|
|
|
metadata.setContentType(multiReq.getContentType()); |
|
|
|
metadata.setContentLength(newFile.length()); |
|
|
|
ResultData data = qrCodeService.awsUpload(new FileInputStream(newFile), metadata, fileName, getTenantId()); |
|
|
|
// 删除本地缓存 |
|
|
|
newFile.delete(); |
|
|
|
return data; |
|
|
|
} else { |
|
|
|
ObjectMetadata metadata = new ObjectMetadata(); |
|
|
|
metadata.setContentType(multiReq.getContentType()); |
|
|
|
metadata.setContentLength(size); |
|
|
|
ResultData data = qrCodeService.awsUpload(multiReq.getInputStream(), metadata, fileName, getTenantId()); |
|
|
|
return data; |
|
|
|
} |
|
|
|
fos.close(); |
|
|
|
fs.close(); |
|
|
|
logger.info("local file: " + localImgFileName); |
|
|
|
File newFile = ImgUtil.thinImage(localImgFileName, localNewImgFileName, imgFormat); |
|
|
|
logger.info("local new file: " + localNewImgFileName); |
|
|
|
// 删除本地缓存 |
|
|
|
localFile.delete(); |
|
|
|
ObjectMetadata metadata = new ObjectMetadata(); |
|
|
|
metadata.setContentType(multiReq.getContentType()); |
|
|
|
metadata.setContentLength(newFile.length()); |
|
|
|
ResultData data = qrCodeService.awsUpload(new FileInputStream(newFile), metadata, fileName, getTenantId()); |
|
|
|
// 删除本地缓存 |
|
|
|
newFile.delete(); |
|
|
|
return data; |
|
|
|
} else { |
|
|
|
ObjectMetadata metadata = new ObjectMetadata(); |
|
|
|
metadata.setContentType(multiReq.getContentType()); |
|
|
|
metadata.setContentLength(size); |
|
|
|
ResultData data = qrCodeService.awsUpload(multiReq.getInputStream(), metadata, fileName, getTenantId()); |
|
|
|
return data; |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -145,13 +150,13 @@ public class UploadController extends BaseController { |
|
|
|
@PostMapping(value = "/awsFilesUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
|
@ApiOperation("多文件上传") |
|
|
|
@SystemControllerLog(description = "多文件上传") |
|
|
|
public ResultData awsFilesUpload(@RequestParam("files") MultipartFile[] files) throws Exception{ |
|
|
|
public ResultData awsFilesUpload(@RequestParam("files") MultipartFile[] files) throws Exception { |
|
|
|
logger.info("[" + getIpAddr() + "] UploadController::awsFilesUpload"); |
|
|
|
|
|
|
|
if(files.length > 0){ |
|
|
|
if (files.length > 0) { |
|
|
|
ResultData data = new ResultData(); |
|
|
|
List<Map<String,String>> dataList = new ArrayList<Map<String,String>>(); |
|
|
|
for(MultipartFile multipartFile: files) { |
|
|
|
List<Map<String, String>> dataList = new ArrayList<Map<String, String>>(); |
|
|
|
for (MultipartFile multipartFile : files) { |
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
|
|
|
|
ObjectMetadata metadata = new ObjectMetadata(); |
|
|
|
@@ -172,8 +177,8 @@ public class UploadController extends BaseController { |
|
|
|
} |
|
|
|
|
|
|
|
ResultData data1 = qrCodeService.awsUpload(multipartFile.getInputStream(), metadata, fileName, getTenantId()); |
|
|
|
if(data1.code == ResultData.SUCCESS) { |
|
|
|
Map _data = (Map)data1.data; |
|
|
|
if (data1.code == ResultData.SUCCESS) { |
|
|
|
Map _data = (Map) data1.data; |
|
|
|
map.put("url", (String) _data.get("url")); |
|
|
|
dataList.add(map); |
|
|
|
} else { |
|
|
|
@@ -200,7 +205,7 @@ public class UploadController extends BaseController { |
|
|
|
*/ |
|
|
|
@PostMapping(value = "/cimgUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
|
|
|
@ApiOperation("内部接口-C端上传图片文件") |
|
|
|
public ResultData cimgUpload(@RequestParam("file") MultipartFile multiReq) throws Exception{ |
|
|
|
public ResultData cimgUpload(@RequestParam("file") MultipartFile multiReq) throws Exception { |
|
|
|
logger.info("[" + getIpAddr() + "] UploadController::cimgUpload"); |
|
|
|
|
|
|
|
ObjectMetadata metadata = new ObjectMetadata(); |
|
|
|
|