|
@ -34,9 +34,7 @@ import java.net.URL;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.Base64;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@ -63,7 +61,7 @@ public class FileUploadService {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public UploadVO uploadImg(InputStream inputStream, String originalFileName,long fileSize,String fastdfs_file_url) throws NoSuchAlgorithmException, IOException, MyException {
|
|
|
public UploadVO uploadImg(InputStream inputStream, String originalFileName,long fileSize,String fastdfs_file_url) throws Exception {
|
|
|
// 得到文件的完整名称 xxx.txt
|
|
|
if( null == inputStream){
|
|
|
throw new FileInputStreamEmptyException("图片文件流不可为空!");
|
|
@ -82,6 +80,10 @@ public class FileUploadService {
|
|
|
throw new FileWrongFormatException("图片文件格式不正确,请上传jpg,jpeg,png等任一格式!");
|
|
|
}
|
|
|
|
|
|
if (!isFileFlag(fileType)){
|
|
|
throw new FileWrongFormatException("不符合文件上传格式");
|
|
|
}
|
|
|
|
|
|
long max = 5*1024*1024;
|
|
|
if(fileSize > max){
|
|
|
throw new FileTooLargeSizeException("图片文件过大,请不要超过5M!");
|
|
@ -164,6 +166,9 @@ public class FileUploadService {
|
|
|
//得到文件类型sentitiveLog.txt
|
|
|
String fileType = originalFileName.substring(originalFileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
String fileName = originalFileName.substring(0, originalFileName.lastIndexOf("."));
|
|
|
if (!isFileFlag(fileType)){
|
|
|
throw new FileWrongFormatException("不符合文件上传格式");
|
|
|
}
|
|
|
//上传到fastdfs
|
|
|
ObjectNode objectNode = fastDFSHelper.upload(inputStream, fileType, "");
|
|
|
//解析返回的objectNode
|
|
@ -198,13 +203,17 @@ public class FileUploadService {
|
|
|
String type = fs[1];
|
|
|
logger.info("uploadImg type:"+type);
|
|
|
//图片常见格式:bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,webp
|
|
|
// List img = new ArrayList(Arrays.asList("bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp"));
|
|
|
// if (!img.contains(type)) {
|
|
|
// map.put("uploadStatus",2);//文件类型不对
|
|
|
// map.put("accessoryUrl",null);//
|
|
|
// return map;
|
|
|
// }
|
|
|
String response = request(wlyyUrl + "/upload/chat", multipartFile, null);
|
|
|
/* List img = new ArrayList(Arrays.asList("bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp"));
|
|
|
if (!img.contains(type)) {
|
|
|
map.put("uploadStatus",2);//文件类型不对
|
|
|
map.put("accessoryUrl",null);//
|
|
|
return map;
|
|
|
}*/
|
|
|
if (!isFileFlag(type)){
|
|
|
throw new FileWrongFormatException("不符合文件上传格式");
|
|
|
}
|
|
|
|
|
|
String response = request(wlyyUrl + "/upload/chat", multipartFile, type);
|
|
|
org.json.JSONObject rs = new org.json.JSONObject(response);
|
|
|
Integer status = (Integer) rs.get("status");
|
|
|
if (status == 200) {
|
|
@ -262,7 +271,7 @@ public class FileUploadService {
|
|
|
// return map;
|
|
|
// }
|
|
|
logger.info("语音文件转换file-转换-multipartFile-成功,开始调用i健康接口上传文件");
|
|
|
String response = request(wlyyUrl + "/upload/chat", multipartFile, null);
|
|
|
String response = request(wlyyUrl + "/upload/chat", multipartFile, type);
|
|
|
org.json.JSONObject rs = new org.json.JSONObject(response);
|
|
|
Integer status = (Integer) rs.get("status");
|
|
|
if (status == 200) {
|
|
@ -307,8 +316,10 @@ public class FileUploadService {
|
|
|
return url;
|
|
|
}
|
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
|
String[] fs = fileName.split("\\.");
|
|
|
String type = fs[1];
|
|
|
logger.info("语音文件转换file-转换-multipartFile-成功,开始调用内网接口上传文件");
|
|
|
String rs = request(remote_inner_url, multipartFile, null);
|
|
|
String rs = request(remote_inner_url, multipartFile, type);
|
|
|
logger.info(rs);
|
|
|
JSONObject json = JSON.parseObject(rs);
|
|
|
uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
|
|
@ -359,8 +370,9 @@ public class FileUploadService {
|
|
|
|
|
|
return fileUrls;
|
|
|
}
|
|
|
|
|
|
logger.info("图片文件转换file-转换-multipartFile-成功,开始调用内网接口上传文件");
|
|
|
String rs = request(remote_inner_url, multipartFile, null);
|
|
|
String rs = request(remote_inner_url, multipartFile, fileContenType);
|
|
|
logger.info(rs);
|
|
|
JSONObject json = JSON.parseObject(rs);
|
|
|
uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
|
|
@ -422,7 +434,7 @@ public class FileUploadService {
|
|
|
// return map;
|
|
|
// }
|
|
|
logger.info("语音文件转换file-转换-multipartFile-成功,开始调用i健康接口上传文件");
|
|
|
String response = request( remoteUrl, multipartFile, null);
|
|
|
String response = request( remoteUrl, multipartFile, type);
|
|
|
JSONObject json = JSON.parseObject(response);
|
|
|
Integer status = json.getInteger("status");
|
|
|
if (status == 200) {
|
|
@ -479,7 +491,7 @@ public class FileUploadService {
|
|
|
// return map;
|
|
|
// }
|
|
|
logger.info("图片文件转换file-转换-multipartFile-成功,开始调用i健康接口上传文件");
|
|
|
String response = request(wlyyUrl + "/upload/chat", multipartFile, null);
|
|
|
String response = request(wlyyUrl + "/upload/chat", multipartFile, type);
|
|
|
org.json.JSONObject rs = new org.json.JSONObject(response);
|
|
|
Integer status = (Integer) rs.get("status");
|
|
|
if (status == 200) {
|
|
@ -506,6 +518,10 @@ public class FileUploadService {
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(type)) {
|
|
|
builder.addTextBody("type", type); //发送类型
|
|
|
}
|
|
|
logger.info("type===="+type);
|
|
|
if (!isFileFlag(type)){
|
|
|
throw new FileWrongFormatException("不符合文件上传格式");
|
|
|
}
|
|
|
HttpEntity entity = builder.build();
|
|
|
httpPost.setEntity(entity);
|
|
|
HttpResponse response = httpClient.execute(httpPost);// 执行提交
|
|
@ -622,6 +638,7 @@ public class FileUploadService {
|
|
|
fastDFSHelper.delete(groupName,fileName);
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
* base64上传图片心脏
|
|
|
* @param jsonData,头像转化后的输入流
|
|
@ -654,5 +671,13 @@ public class FileUploadService {
|
|
|
return uploadVO;
|
|
|
}
|
|
|
|
|
|
|
|
|
public boolean isFileFlag(String type){
|
|
|
List img = new ArrayList(Arrays.asList("bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp","xls","xlsx","text/plain"));
|
|
|
if (!img.contains(type)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|