? ? ? 前言~?前段時間做項目用到了bootstrap里中的文件上傳控件,對此特定寫這篇文章,講述一下bootstrap的文件上傳空間的使用方法。
我們進入正題吧!
? ? ? ?首先bootstrap是基于jquery的,因此要導入jquery響應jar包,可以找到以下網站:jquery相關js下載。
進入網址后,可以選擇我圈起來的地址,打開瀏覽器輸入,并將該js的所有內容復制下來,創建一個" .js "文件存儲這些內容作為jquery.js使用。
? ? ? ?其次要下載bootstrap的文件包,相必你們已經有了,那么我就只推出下載fileinput的相關文件包即可,以下是下載地址下載fileinput相關文件包。
? ? ? ?再次分別導入bootstrap和fileinput的相關css文件,js文件,如下所示:
<link?rel="stylesheet"?href="../static/css/bootstrap.css">
<link?rel="stylesheet" href="../static/css/fileinput.min.css">
<link rel="stylesheet"?href="../static/css/themes/theme.css">
<script type="text/javascript" src="../static/js/jquery-3.3.1.min.js"></script>
<script?type="text/javascript" src="../static/js/fileinput.min.js"></script>
<script type="text/javascript" src="../static/js/locales/zh.js"></script>
<script?type="text/javascript" src="../static/js/themes/theme.js"></script>
? ? ? ?后面可以選擇兩種方式配置fileinput的相關屬性,一種是在jsp或者html中直接配置,第二種是寫一個js,然后將該js引入。本人推薦使用第二種,因為比較靈活。下面我都列出兩種方式。
第一種:
<div?class="container kv-main">
<div?class="row ">
<div style="margin:100px 240px;width:700px;height:300px ">
<form?nctype="multipart/form-data">
<input?id="file-0a" class="file" name="file" type="file" multiple data-min-file-count="1">
<br>
</form>
</div>
</div>
<script>
$('#file-0a').fileinput({
'theme':'explorer',
language:'zh',
uploadUrl:'<%=path%>/uploadMultipleFile.do',
showPreview:true,//是否顯示預覽
? ? allowedPreviewTypes : ['image','html','text','video','audio','flash'],
maxFileCount :3,// 表示允許同時上傳的最大文件個數
});
$('#file-0a').on('fileuploaderror',function(event, data, previewId, index) {
var form = data.form,files = data.files,extra = data.extra,
response = data.response,reader = data.reader;
console.log(data);
console.log('File upload error');
});
$('#file-0a').on('fileerror',function(event, data) {
console.log(data.id);
console.log(data.index);
console.log(data.file);
console.log(data.reader);
console.log(data.files);
});
$('#file-0a').on('fileuploaded',function(event, data, previewId, index) {
var form = data.form,files = data.files,extra = data.extra,
response = data.response,reader = data.reader;
console.log('File uploaded triggered');
});
</script>
第二種:
$(function () {
? ? //0.初始化fileinputvaroFileInput =new FileInput();
? ? oFileInput.Init("file-0a", "/api/OrderApi/ImportOrder");
});
//初始化fileinputvarFileInput =function () {
? ? varoFile =new Object();
? ? //初始化fileinput控件(第一次初始化)oFile.Init =function(ctrlName, uploadUrl) {
? ? varcontrol = $('#' + ctrlName);
? ? //初始化上傳控件的樣式? ? control.fileinput({
? ? ? ? language: 'zh',//設置語言
? ? ? ? uploadUrl: uploadUrl,//上傳的地址
? ? ? ? allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后綴
? ? ? ? showUpload:true,//是否顯示上傳按鈕
? ? ? ? showCaption:false,//是否顯示標題
? ? ? ? browseClass: "btn btn-primary",//按鈕樣式
? ? ? ? //dropZoneEnabled: false,//是否顯示拖拽區域
? ? ? ? //minImageWidth: 50, //圖片的最小寬度
? ? ? ? //minImageHeight: 50,//圖片的最小高度
? ? ? ? //maxImageWidth: 1000,//圖片的最大寬度
? ? ? ?//maxImageHeight: 1000,//圖片的最大高度
? ? ? ?//maxFileSize: 0,//單位為kb,如果為0表示不限制文件大小
? ? ? ?//minFileCount: 0,maxFileCount: 10, //表示允許同時上傳的最大文件個數
? ? ? ? enctype: 'multipart/form-data',
? ? ? ? validateInitialCount:true,
? ? ? ? previewFileIcon: "",
? ? ? ? msgFilesTooMany: "選擇上傳的文件數量({n}) 超過允許的最大數值{m}!",? ? });
? ? //導入文件上傳完成之后的事件
$('#file-0a').on('fileuploaderror',function(event, data, previewId, index) {
var form = data.form,files = data.files,extra = data.extra,
response = data.response,reader = data.reader;
console.log(data);
console.log('File upload error');
});
$('#file-0a').on('fileerror',function(event, data) {
console.log(data.id);
console.log(data.index);
console.log(data.file);
console.log(data.reader);
console.log(data.files);
});
$('#file-0a').on('fileuploaded',function(event, data, previewId, index) {
var form = data.form,files = data.files,extra = data.extra,
response = data.response,reader = data.reader;
console.log('File uploaded triggered');
});
}
? ? return oFile;
};
以下將提供fileinput的相關api
屬性名? ? ? ?屬性類型? ? ?描述? ? ?說明? ? ? 默認值
language? ? ?String? ? 多語言設置,使用時需提前引入\locales文件夾下對應的語言文件,
中文zh,引入語言文件必須放在fileinput.js之后? ? ? ? ? ? ? ? ? ? 'en'
showCaption? ? ?Boolean? ? ?是否顯示被選文件的簡介? ? ? ? ? true
showBrowse? ? ? Boolean? ? ?是否顯示瀏覽按鈕? ? ? ? ? ? ? ? ? ? true
showPreview? ? ? Boolean? ? 是否顯示預覽區域? ? ? ? ? ? ? ? ? ? true
showRemove? ? ? Boolean? ? 是否顯示移除按鈕? ? ? ? ? ? ? ? ? ?true,
showUpload? ? ? ? Boolean? ? 是否顯示上傳按鈕? ? ? ? ? ? ? ? ? ?true,
showCancel? ? ? ? Boolean? ? 是否顯示取消按鈕? ? ? ? ? ? ? ? ? ?true,
showClose:? ? ? ? ?Boolean? ? 是否顯示關閉按鈕? ? ? ? ? ? ? ? ? ?true
showUploadedThumbs? ? ? ?Boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? true
browseOnZoneClick? ? ? ? ? ? Boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?false
autoReplace? ? ? ? ? ? ? ? ? ? ? ? Boolean? ? ? ? 是否自動替換當前圖片,設置為true時,再次選擇文件,
會將當前的文件替換掉。? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? false
generateFileId? ? ? ? ? ? ? ? ? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? null
previewClass? ? ? ? ? ? ? ? ? ? ? String? ? 添加預覽按鈕的類屬性? ? ? ? ? ‘’
captionClass? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ‘’
frameClass? ? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'krajee-default'
mainClass? ? ? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'file-caption-main'
mainTemplate? ? ? ? ? ? ? ? ? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
purifyHtml? ? ? ? ? ? ? ? ? ? ? ? ? ?Boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? true
fileSizeGetter? ? ? ? ? ? ? ? ? ? ? Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
initialCaption? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?''
initialPreview? ? ? ? ? ? ? ? ? ?Array/Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[]
initialPreviewDelimiter? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'*$$*'
initialPreviewAsData? ? ? ? ? ?Boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? false
initialPreviewFileType? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'image'
initialPreviewConfig? ? ? ? ? Array/Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[]
initialPreviewThumbTags? ? Array/Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?[]
previewThumbTags? ? ? ? ? ? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {}
initialPreviewShowDelete? ? ? ?Boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? true
removeFromPreviewOnError? Boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?false
deleteUrl? ? ? ? ? ? String? ? ? ? ? ?刪除圖片時的請求路徑? ? ? ? ? ? ? ? ''
deleteExtraData? ?Object? ? ? ?刪除圖片時額外傳入的參數? ? ? ? ?{}
overwriteInitial? ? ? Boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? true
previewZoomButtonIcons? ? ? ? ? ?Object
?{
? ?prev: '',
? next: '',
? toggleheader: '',
? fullscreen: '',
? borderless: '',
??close: ''
},
previewZoomButtonClasses? ? ? ?Object
? {?
prev: 'btn btn-navigate',
? next: 'btn btn-navigate',
? toggleheader: 'btn btn-default btn-header-toggle',
? fullscreen: 'btn btn-default',
? borderless: 'btn btn-default',
? close: 'btn btn-default'
},
preferIconicPreview? ? ? ? ? ? ? ?Boolrean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?false
preferIconicZoomPreview? ? ? ?Boolrean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? false
allowedPreviewTypes? ? ? ? ? ? ?undefined? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?undefined
allowedPreviewMimeTypes? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
allowedFileTypes? ? ? ? ? ? ? ? ? ? ?Object? ? ? ? ? ? 接收的文件后綴,如['jpg', 'gif', 'png'],不填將不限制上傳文件后綴類型? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
allowedFileExtensions? ? ? ? ? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
defaultPreviewContent? ? ? ? ? ? Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
customLayoutTags? ? ? ? ? ? ? ? ? Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{}
customPreviewTags? ? ? ? ? ? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {}
previewFileIcon? ? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?''
previewFileIconClass? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'file-other-icon'
previewFileIconSettings? ? ? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {}
previewFileExtSettings? ? ? ? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {}
buttonLabelClass? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'hidden-xs'
browseIcon? ? ? ? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ' '
browseClass? ? ? ? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'btn btn-primary'
removeIcon? ? ? ? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ''
removeClass? ? ? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'btn btn-default'
cancelIcon? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ''
cancelClass? ? ? ? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'btn btn-default'
uploadIcon? ? ? ? ? ? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ''
uploadClass? ? ? ? ? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'btn btn-default'
uploadUrl? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ?上傳文件路徑? ? ? ? ? null
uploadAsync? ? ? ? ? ? ? ? ? ? ? ? ? boolean? ? 是否為異步上傳? ? ? true
uploadExtraData? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?上傳文件時額外傳遞的參數設置? ? ? ? ? {}
zoomModalHeight? ? ? ? ? ? ? ? number? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?480
minImageWidth? ? ? ? ? ? ? ? ? ? String? ? ? ? ? 圖片的最小寬度? ? ?null
minImageHeight? ? ? ? ? ? ? ? ? String? ? ? ? ? ?圖片的最小高度? ? ? null
maxImageWidth? ? ? ? ? ? ? ? ? String? ? ? ? ? ?圖片的最大寬度? ? ? null
maxImageHeight? ? ? ? ? ? ? ? String? ? ? ? ? ? 圖片的最大高度? ? ? null
resizeImage? ? ? ? ? ? ? ? ? ? ? ? boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? false
resizePreference? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'width'
resizeQuality? ? ? ? ? ? ? ? ? ? ? number? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0.92
resizeDefaultImageType? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'image/jpeg'
minFileSize? ? ? ? ? ? ? ? ? ? ? ? ? number? ? 單位為kb,上傳文件的最小大小值? ? ?0
maxFileSize? ? ? ? ? ? ? ? ? ? ? ? ?number? ? 單位為kb,如果為0表示不限制文件大小? ? 0
resizeDefaultImageType? ? ? number? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 25600(25MB)
minFileCount? ? ? ? ? ? ? ? ? ? ? ?number? ? ?表示同時最小上傳的文件個數? ? ? ? ? ? ? ? ? ? 0
maxFileCount? ? ? ? ? ? ? ? ? ? ? number? ? 表示允許同時上傳的最大文件個數? ? ? ? ? ? ? 0
validateInitialCount? ? ? ? ? ? ? boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? false
msgValidationErrorClass? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'text-danger'
msgValidationErrorIcon? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?' '
msgErrorClass? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 'file-error-message'
progressThumbClass? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"progress-bar progress-bar-success progress-bar-striped active"
rogressClass? ? ? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"progress-bar progress-bar-success progress-bar-striped active"
progressCompleteClass? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? "progress-bar progress-bar-success"
progressErrorClass? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"progress-bar progress-bar-danger"
progressUploadThreshold? ? number? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?99
previewFileType? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? 預覽文件類型,內置['image', 'html', 'text', 'video', 'audio', 'flash', 'object',‘other‘]等格式? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'image'
elCaptionContainer? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? null
elCaptionText? ? ? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ?設置標題欄提示信息? ? ? ? ? ? ? null
elPreviewContainer? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
elPreviewImage? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
elPreviewStatus? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
elErrorContainer? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?null
errorCloseButton? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '×'
slugCallback? ? ? ? ? ? ? ? ? ? ? ? String? ? ? ? ? ? ?暫時沒有搜到說明,調試顯示,在文件選擇后會調到這個方法。? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? null
dropZoneEnabled? ? ? ? ? ? ? ? boolean? ? ? ?是否顯示拖拽區域? ? ? ? ? ? ? ? ? ? ?true
dropZoneTitleClass? ? ? ? ? ? ? String? ? ? ? ? 拖拽區域類屬性設置? ? ? ? ?'file-drop-zone-title'
fileActionSettings? ? ? ? ? ? ? ? ?Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {}
otherActionButtons? ? ? ? ? ? ? String? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ''
textEncoding? ? ? ? ? ? ? ? ? ? ? ?String? ? ? ? ? ? ? ? ? 編碼設置? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'UTF-8'
ajaxSettings? ? ? ? ? ? ? ? ? ? ? ? Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {}
ajaxDeleteSettings? ? ? ? ? ? ? Object? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {}
showAjaxErrorDetails? ? ? ? ?boolean? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?true
7、Method說明:
方法名參數描述
fileerror?異步上傳錯誤結果處理
$('#uploadfile').on('fileerror', function(event, data, msg) {
});
fileuploaded?異步上傳成功結果處理
$("#uploadfile").on("fileuploaded", function (event, data, previewId, index) {
})
filebatchuploaderror?同步上傳錯誤結果處理
$('#uploadfile').on('filebatchuploaderror', function(event, data, msg) {
});
filebatchuploadsuccess?同步上傳成功結果處理
$('#uploadfile').on('filepreupload', function(event, data, previewId, index) {? ??
});
filebatchselected?選擇文件后處理事件
$("#fileinput").on("filebatchselected", function(event, files) {
});
upload?文件上傳方法
$("#fileinput").fileinput("upload");
fileuploaded?上傳成功后處理方法
$("#fileinput").on("fileuploaded", function(event, data, previewId, index) {
});
filereset??
fileclear?點擊瀏覽框右上角X 清空文件前響應事件
$("#fileinput").on("fileclear",function(event, data, msg){
});
filecleared?點擊瀏覽框右上角X 清空文件后響應事件
$("#fileinput").on("filecleared",function(event, data, msg){
});
fileimageuploaded?在預覽框中圖片已經完全加載完畢后回調的事件
? ?后臺代碼
/**
* 多文件上傳
* @param files 文件數組
* @param request
* @return
* @throws IOException
*/
@RequestMapping(value ="/uploadMultipleFile.do", method = RequestMethod.POST, produces ="application/json;charset=utf8")
@ResponseBody
public Message uploadMultipleFileHandler(@RequestParam("file") MultipartFile[] files, HttpServletRequest request)throws IOException {
Message msg =new Message();
ArrayList arr =new ArrayList();
String serverPath=null;
for (int i =0; i < files.length; i++) {
MultipartFile file = files[i];
if (!file.isEmpty()) {
InputStream in =null;
OutputStream out =null;
try {
if(file.getOriginalFilename().substring(0,file.getOriginalFilename().indexOf(".")).contains("表1-惡意程序監測統計")){
serverPath=FileUtil.getMalwareUploadDirFilePath(file.getOriginalFilename(), request);
}else{
serverPath=FileUtil.getHighRiskUploadDirFilePath(file.getOriginalFilename(), request);
}
/*String serverPath=dir.getAbsolutePath() + File.separator + file.getOriginalFilename();*/
? ? ? ? ? ? ? ? File serverFile =new File(serverPath);
in = file.getInputStream();
out =new FileOutputStream(serverFile);
byte[] b =new byte[1024];
int len =0;
while ((len = in.read(b)) >0) {
out.write(b,0, len);
}
out.close();
in.close();
logger.info("Server File Location=" + serverFile.getAbsolutePath());
}catch (Exception e) {
arr.add(i);
}finally {
if (out !=null) {
out.close();
out =null;
}
if (in !=null) {
in.close();
in =null;
}
}
}else {
arr.add(i);
}
}
if(arr.size() >0) {
msg.setStatus(Status.ERROR);
msg.setError("Files upload fail");
msg.setErrorKys(arr);
}else {
msg.setStatus(Status.SUCCESS);
msg.setStatusMsg("Files upload success");
}
return msg;
}