Bootstrap之fileinput文件上傳控件

? ? ? 前言~?前段時間做項目用到了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;

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,908評論 6 541
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,324評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,018評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,675評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,417評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,783評論 1 329
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,779評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,960評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,522評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,267評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,471評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,009評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,698評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,099評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,386評論 1 294
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,204評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,436評論 2 378