Commit e68668a2 authored by guozhipeng's avatar guozhipeng

上传文件

parent 32fb5585
......@@ -2790,8 +2790,7 @@ sap.ui.define(
var headers = {};//headers: headers,
if (that.getStorage().get("csrfToken") != null && that.getStorage().get("csrfToken") !== undefined) {
headers = {
'x-csrf-token': that.getStorage().get("csrfToken"),
'Content-Type': 'application/json'
'x-csrf-token': that.getStorage().get("csrfToken")
};
}
headers.language=that.language;
......@@ -3360,8 +3359,7 @@ sap.ui.define(
var headers = {};//headers: headers,
if (that.getStorage().get("csrfToken") != null && that.getStorage().get("csrfToken") !== undefined) {
headers = {
'x-csrf-token': that.getStorage().get("csrfToken"),
'Content-Type': 'application/json'
'x-csrf-token': that.getStorage().get("csrfToken")
};
}
headers.language=that.language;
......
......@@ -348,8 +348,7 @@ sap.ui.define(
var headers = {};//headers: headers,
if (that.getStorage().get("csrfToken") != null && that.getStorage().get("csrfToken") !== undefined) {
headers = {
'x-csrf-token': that.getStorage().get("csrfToken"),
'Content-Type': 'application/json'
'x-csrf-token': that.getStorage().get("csrfToken")
};
}
headers.language=that.language;
......
......@@ -341,8 +341,7 @@ sap.ui.define(
var headers = {};//headers: headers,
if (that.getStorage().get("csrfToken") != null && that.getStorage().get("csrfToken") !== undefined) {
headers = {
'x-csrf-token': that.getStorage().get("csrfToken"),
'Content-Type': 'application/json'
'x-csrf-token': that.getStorage().get("csrfToken")
};
}
headers.language=that.language;
......
......@@ -2048,16 +2048,21 @@ sap.ui.define(
let userAuthentication = this.loginInfo.userAuthentication;
let appKey = userAuthentication.appKey;
var headers = {};//headers: headers,
if (that.getStorage().get("csrfToken") != null && that.getStorage().get("csrfToken") !== undefined) {
headers = {
'x-csrf-token': that.getStorage().get("csrfToken")
};
}
headers.language=that.language;
headers.appKey=appKey;
$.ajax({
url: this.baseUrl + "attachment/batchUpload",
type: "POST",
headers: headers,
data: formData,
processData: false,
contentType: false,
headers: {
'appKey':appKey
},
success: function(res) {
if(res.success){
let fileList = res.result;
......
......@@ -1871,16 +1871,21 @@ sap.ui.define(
let userAuthentication = this.loginInfo.userAuthentication;
let appKey = userAuthentication.appKey;
var headers = {};//headers: headers,
if (that.getStorage().get("csrfToken") != null && that.getStorage().get("csrfToken") !== undefined) {
headers = {
'x-csrf-token': that.getStorage().get("csrfToken")
};
}
headers.language=that.language;
headers.appKey=appKey;
$.ajax({
url: this.baseUrl + "attachment/batchUpload",
type: "POST",
headers: headers,
data: formData,
processData: false,
contentType: false,
headers: {
'appKey':appKey
},
success: function(res) {
if(res.success){
let fileList = res.result;
......
......@@ -4331,8 +4331,7 @@ sap.ui.define(
var headers = {};//headers: headers,
if (that.getStorage().get("csrfToken") != null && that.getStorage().get("csrfToken") !== undefined) {
headers = {
'x-csrf-token': that.getStorage().get("csrfToken"),
'Content-Type': 'application/json'
'x-csrf-token': that.getStorage().get("csrfToken")
};
}
headers.language=that.language;
......
......@@ -146,6 +146,11 @@ common(){
starttime=`date +%s`
secondsToTime "${starttime}" "${starttime}"
#登录BTP 输入密码: Gzp@123456 后回车。
echo -e "\033[30;42m 登录BTP test 子账户 输入密码: Gzp@123456 后回车 \033[0m"
# 登录BTP命令:
cf login -a https://api.cf.cn40.platform.sapcloud.cn -o "Shenzhen-Lianchuangjie-Technology-Co-Ltd-test-cnrc164l" -s gzpTest -u zhipeng.guo@boscloud.cn
#校验登录状态
account=$(cf services)
accountMatch='.*succeeded.*'
......
......@@ -36,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartResolver;
import static customer.lianchuangjie.common.util.ConvertUtils.getSuffix;
......@@ -54,6 +55,8 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentDao, Attachment
private AttachmentProductBatchDao attachmentProductBatchDao;
@Autowired
private GoldSampleDao goldSampleDao;
@Autowired
private MultipartResolver multipartResolver;
/**
* 批量上传
......@@ -65,39 +68,51 @@ public class AttachmentServiceImpl extends ServiceImpl<AttachmentDao, Attachment
@Transactional(rollbackFor = Exception.class)
public Result<?> batchUpload(HttpServletRequest request, String language) {
String message = "";
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
List<JSONObject> results = new ArrayList<>();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
JSONObject item = new JSONObject();
MultipartFile file = entity.getValue();// 获取上传文件对象
try {
if (file != null) { // 文件不为空
String originalFilename = file.getOriginalFilename();
long size = file.getSize();
String contentType = file.getContentType();
String fileId = FileServerUtil.upload(file.getInputStream(), file.getOriginalFilename(), FileServerUtil.Timeout.BEST);
item.put("fileId", fileId);//文件服务器生成的文件ID
item.put("fileName", originalFilename);//原始文件名
item.put("fileSize", size);//文件大小 字节 byte
item.put("contentType", contentType);//文件类型
item.put("fileSuffix", getSuffix(originalFilename));//文件后缀名
results.add(item);
} else {
throw new BtpException(MessageUtil.get("paramNotEmpty", new Object[] { "" }, language));
}
} catch (Exception e) {
message = "" + (e.getMessage() != null ? e.getMessage() : e);
log.error(message);
throw new BtpException(MessageUtil.get("error", new Object[] { message }, language));
} finally {
// 获取原始请求对象
HttpServletRequest originalRequest = request;
while (originalRequest instanceof javax.servlet.http.HttpServletRequestWrapper) {
originalRequest = (HttpServletRequest) ((javax.servlet.http.HttpServletRequestWrapper) originalRequest).getRequest();
log.info("[originalRequest instanceof javax.servlet.http.HttpServletRequestWrapper]true");
}
if (multipartResolver.isMultipart(originalRequest)) {
log.info("[multipartResolver.isMultipart(originalRequest)]true");
MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(originalRequest);
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
log.info("[fileMap.entrySet()]for");
JSONObject item = new JSONObject();
MultipartFile file = entity.getValue();// 获取上传文件对象
try {
file.getInputStream().close();
} catch (IOException e) {
if (file != null) { // 文件不为空
String originalFilename = file.getOriginalFilename();
long size = file.getSize();
String contentType = file.getContentType();
String fileId = FileServerUtil.upload(file.getInputStream(), file.getOriginalFilename(), FileServerUtil.Timeout.BEST);
item.put("fileId", fileId);//文件服务器生成的文件ID
item.put("fileName", originalFilename);//原始文件名
item.put("fileSize", size);//文件大小 字节 byte
item.put("contentType", contentType);//文件类型
item.put("fileSuffix", getSuffix(originalFilename));//文件后缀名
results.add(item);
} else {
throw new BtpException(MessageUtil.get("paramNotEmpty", new Object[] { "" }, language));
}
} catch (Exception e) {
message = "" + (e.getMessage() != null ? e.getMessage() : e);
log.error(message);
throw new BtpException(MessageUtil.get("error", new Object[] { message }, language));
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
message = "" + (e.getMessage() != null ? e.getMessage() : e);
log.error(message);
}
}
}
} else {
log.info("[multipartResolver.isMultipart(originalRequest)]false");
}
if (results.size() > 0) {
Result<Object> ok = Result.ok(MessageUtil.get("success", new Object[] { message }, language));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment