bootstrap⽂件上传fileupload插件源码以及API地址:
前后端单⽂件上传代码:
@ResponseBody
@RequestMapping(value="/upload", method = RequestMethod.POST)
public JSONObject upload(@RequestParam("file") MultipartFile file, HttpServletRequest request ) {
System.out.println("上传开始");
JSONObject json = new JSONObject();
json.put("code", "1");
if( file.isEmpty() ) {
json.put("msg", "上传⽂件为空");
return json;
}else {
String savePath = ServletContext().getRealPath("/upload/");
String OriginalFilename();
String pathname = savePath + fileName;
File dest = new File(pathname);
if( !ParentFile().exists() ) {
}
try {
linux基本命令tar
json.put("code", 1);
json.put("msg", "上传成功");
json.put("imgPath", pathname);
return json;
} catch (Exception e) {
smart分析json.put("msg", e.getMessage());
return json;
}
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = ContextPath();
String basePath = Scheme() + "://" + ServerName() + ":" + ServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<!-- release v4.1.8, copyright 2014 - 2015 Kartik Visweswaran -->
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>上传⽂件测试</title>
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet">
<link href="<%=basePath%>css/fileinput.min.css" media="all" rel="stylesheet" type="text/css"/>
<script src="<%=basePath%>js/jquery-3.2.1.min.js"></script>
<script src="<%=basePath%>js/fileinput.min.js" type="text/javascript"></script>
<script src="<%=basePath%>js/fileinput_locale_zh.js" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
<div class="row" >
<input id="file-0" class="file" type="file" multiple data-min-file-count="1" name="file">
</div>
</div>jquery的版本
<script type="text/javascript">
//初始化fileinput控件(第⼀次初始化)
function initFileInput(ctrlName, uploadUrl) {
var control = $('#' + ctrlName);
control.fileinput({
language: 'zh', //设置语⾔
uploadUrl: uploadUrl, //上传的地址
allowedFileExtensions : ['jpg', 'png','gif'],//接收的⽂件后缀
showUpload: true, //是否显⽰上传按钮
title翻译成中文是什么意思showCaption: false,//是否显⽰标题
jquery下载文件插件
browseClass: "btn btn-primary", //按钮样式
previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
});
}
//初始化fileinput控件(第⼀次初始化)
initFileInput("file-0", "/upload");
</script>
alice springs</body>
</html>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。