bootstrap fileinput 文件上传和回显「建议收藏」

bootstrap fileinput 文件上传和回显「建议收藏」官网下载文件http://plugins.krajee.com/file-input/demobootstrapfileinput是基于bootstrap基础上的上传插件,so必要的bootstrap文件是要引用的…1.引用js和css文件fileinput.cssfileinput.min.js中文字体2.初始化fileinput前台jsp:<…

大家好,又见面了,我是你们的朋友全栈君。

官网下载文件http://plugins.krajee.com/file-input/demo

bootstrap fileinput 是基于bootstrap基础上的上传插件,so必要的bootstrap文件是要引用的…

1.引用js和css文件

fileinput.css

fileinput.min.js

中文字体

2.初始化fileinput

前台

jsp:

<input id="debugId" name="debugId" hidden="true" /> <!-- 文件上传额外参数 -->

<input id="fileInput" name="files" multiple type="file" class="file" value=""/>

如果已经存在,换个名字即可,如class=”file1″class

js:

step1:上传部分,可携带额外参数
$("#fileInput").fileinput('destroy');  // 直接销毁
            	$("#fileInput").fileinput({
                    language: 'zh', //设置语言
                    uploadUrl: GLOBAL.URL+'project/saveFile.do', //上传的地址 http;//localhost:8080/project/saveFile.do
                    showUpload: false, //是否显示上传按钮
                    showCaption: false,//是否显示标题        
                    previewFileIcon: "<i class='glyphicon glyphicon-king'></i>", 
                    maxFileCount: 6, //表示允许同时上传的最大文件个数
                    fileActionSettings:{showUpload: false}, // 控制上传按钮是否显示
                    uploadExtraData: function(previewId, index) {   //额外参数
                        var obj = {};
                        obj.id = fodderType(); // 这里回调方法
                        return obj;
                    },
                    preferIconicPreview: true, // 开启用图标替换预览效果
   previewFileIconSettings: { // configure your icon file extensions
       'doc': '<i class="fa fa-file-word-o text-primary"></i>',
       'xls': '<i class="fa fa-file-excel-o text-success"></i>',
       'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
       'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
       'txt': '<i class="fa fa-file-text-o text-info"></i>',
       'zip': '<i class="fa fa-file-archive-o text-muted"></i>',
       'htm': '<i class="fa fa-file-code-o text-info"></i>',
       'mov': '<i class="fa fa-file-movie-o text-warning"></i>',
       'mp3': '<i class="fa fa-file-audio-o text-warning"></i>'
   },
previewFileExtSettings: {
       'doc': function(ext) {
           return ext.match(/(doc|docx)$/i);
       },
       'xls': function(ext) {
           return ext.match(/(xls|xlsx)$/i);
       },
       'ppt': function(ext) {
           return ext.match(/(ppt|pptx)$/i);
       },
       'zip': function(ext) {
           return ext.match(/(zip|rar|tar|gzip|gz|7z)$/i);
       },
       'htm': function(ext) {
           return ext.match(/(htm|html)$/i);
       },
       'mov': function(ext) {
           return ext.match(/(avi|mpg|mkv|mov|mp4|3gp|webm|wmv)$/i);
       },
       'mp3': function(ext) {
           return ext.match(/(mp3|wav)$/i);
       },
       'txt': function(ext) {
           return ext.match(/(txt|ini|csv|java|php|js|css)$/i);
       }
   },
   layoutTemplates:{ // 预览图片按钮控制,这里屏蔽预览按钮
   	actionZoom:''
   }
});
fodderType = function() {
    return $("#debugId").val();

};

step2:单独调用上传
$("#fileInput").fileinput("upload");

step3:控件回显重新初始化
// 假设后台信息已经查询完毕!假设为data!!

                            $("#fileInput").fileinput('destroy');
            				$("#fileInput").fileinput({
            			    	language: 'zh', //设置语言
            			        uploadUrl: GLOBAL.URL+'project/saveFile.do?id='+bugId, //上传的地址
            			        showUpload: false, //是否显示上传按钮
            			        showCaption: false,//是否显示标题        
            			        maxFileCount: 6, //表示允许同时上传的最大文件个数
            			        fileActionSettings:{showUpload: false},//是否显示上文件上的上传按钮
            					overwriteInitial: false,
            					allowedPreviewTypes: ['image'],
            					/*
                                !这里是预览的数据格式
                                initialPreview: [
            						// IMAGE RAW MARKUP
            						'http://localhost:8080/amp/base/imgs/app-default.jpg',
            						// IMAGE RAW MARKUP
            						'http://localhost:8080/amp/base/imgs/app-default.jpg',
            						// TEXT RAW MARKUP
            						'123asd啊实打实',
            						'http://localhost:8080/amp/base/imgs/123.docx'
            					],*/
            					initialPreview : data.initialPreview,
            					initialPreviewAsData: true, // allows you to set a raw markup
            					initialPreviewFileType: 'image', // image is the default and can be overridden in config below
            					initialPreviewDownloadUrl: GLOBAL.URL+'project/downFile.do?image={key}', 
            					/*
                                !这里是回显的数据格式,后台查询后,按照格式展示即可,url是删除访问地址,key是删除的id
                                initialPreviewConfig: [
            						{type: "image", caption: "Image-1.jpg", size: 847000, url: "/amp/project/delFile.do", key: 1},
            						{type: "image", caption: "Image-2.jpg", size: 817000, url: "/amp/project/delFile.do", key: '1519713821098wwp4h8v'},  // set as raw markup
            						{type: "text", size: 1430, caption: "LoremIpsum.txt", url: "/amp/project/delFile.do", key: 3},
            						{type: "office", size: 102400, caption: "123.docx", url: "/amp/project/delFile.do", key: '1519788281200pwxfx87'}
            					],*/
            					initialPreviewConfig : data.initialPreviewConfig,
            				       preferIconicPreview: true, // this will force thumbnails to display icons for following file extensions
            				    previewFileIconSettings: { // configure your icon file extensions
            				        'doc': '<i class="fa fa-file-word-o text-primary"></i>',
            				        'xls': '<i class="fa fa-file-excel-o text-success"></i>',
            				        'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
            				        'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
            				        'txt': '<i class="fa fa-file-text-o text-info"></i>',
            				        'zip': '<i class="fa fa-file-archive-o text-muted"></i>',
            				        'htm': '<i class="fa fa-file-code-o text-info"></i>',
            				        'mov': '<i class="fa fa-file-movie-o text-warning"></i>',
            				        'mp3': '<i class="fa fa-file-audio-o text-warning"></i>'
            				    },
            					previewFileExtSettings: { // configure the logic for determining icon file extensions
            				        'doc': function(ext) {
            				            return ext.match(/(doc|docx)$/i);
            				        },
            				        'xls': function(ext) {
            				            return ext.match(/(xls|xlsx)$/i);
            				        },
            				        'ppt': function(ext) {
            				            return ext.match(/(ppt|pptx)$/i);
            				        },
            				        'zip': function(ext) {
            				            return ext.match(/(zip|rar|tar|gzip|gz|7z)$/i);
            				        },
            				        'htm': function(ext) {
            				            return ext.match(/(htm|html)$/i);
            				        },
            				        'mov': function(ext) {
            				            return ext.match(/(avi|mpg|mkv|mov|mp4|3gp|webm|wmv)$/i);
            				        },
            				        'mp3': function(ext) {
            				            return ext.match(/(mp3|wav)$/i);
            				        },
            				        'txt': function(ext) {
            				            return ext.match(/(txt|ini|csv|java|php|js|css)$/i);
            				        }
            				    },
            				    layoutTemplates:{
            				    	actionZoom:''
            				    },
            					uploadExtraData: {
            						img_key: "1000",
            						img_keywords: "happy, nature"
            					}
            				});

 

                

后台上传:

@RequestMapping("/saveFile")
	@ResponseBody
	public String saveFile(@RequestParam(value="files") MultipartFile file,
			HttpServletRequest request,HttpServletResponse response){
		OutputStream os = null;
		InputStream is = null;
		boolean returnBoolean = false; 
		String bug_id = request.getParameter("id");   // 传过来的额外参数
		try {
			String path = "E:\\WORK\\TOMCAT\\apache-tomcat-8.5.24-amp\\wtpwebapps\\amp";
			SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");   
			String currentDate = df.format(System.currentTimeMillis());
			String pathTemp = path + File.separator + currentDate + File.separator + bug_id;
			File fileTemp = new File(pathTemp);
			if(!fileTemp.exists()) {
				fileTemp.mkdirs();
			}
			String fullFilePath = pathTemp + File.separator + file.getOriginalFilename();
			File fullFile = new File(fullFilePath);
			
			os = new FileOutputStream(fullFile);
			is =file.getInputStream();
			byte buf[] = new byte[1024];//可以修改 1024 以提高读取速度
			int length = 0;
			while( (length = is.read(buf)) > 0 ){
				os.write(buf, 0, length);
			}
			returnBoolean = true;
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
            if(is !=null) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(os !=null) {
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return JSONObject.fromObject("{\"success\":"+ returnBoolean +"}").toString();
	}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/134055.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 小旋风asp服务器出错_小旋风服务器用来干什么的

    小旋风asp服务器出错_小旋风服务器用来干什么的 点击是出现下列的对话框:可能是因为因为开着迅雷,因为迅雷是用的80号端口,可以关了迅雷试试,

    2022年10月24日
  • idea社区版_idea社区版够用吗

    idea社区版_idea社区版够用吗IDEA官网地址:https://www.jetbrains.com/idea/download/#section=windows下载社区版后,点击安装,就进行傻瓜式的安装了。以上两个步骤中有一个点击next的时候时间会稍稍有点久,耐心等待一下就好了。点击安装,IDEA社区版就安装完成了,安装好之后打开IDEA工具,会有如下提示:我是第一次使用,直接选择Donotimportsettings就行了。到这里就进入IDEA工具了,选择你喜欢的主题风格,当然这还不算正式的完成,我

    2022年9月2日
  • 最新仿金蝶电商ERP进销存系统软件源码 销售库存仓库财务管理收银系统网络版「建议收藏」

    最新仿金蝶电商ERP进销存系统软件源码 销售库存仓库财务管理收银系统网络版「建议收藏」源码说明:超强的工作流系统,强大的可视化工作流编辑器,灵活自定义表单设计,充分实现企业基于工作流的各项业务管理,与其他模块数据(如HRM等)完美结合。全面综合的任务系统,实现基于信息录入、单据管理、业务协作、工作流转、任务提醒、统计分析等的智能管理。所有单据均支持上传附件功能;且报价单、销售合同、采购订单、发货出库、入库单、派工单等所有模板均支持自定义编辑打印。集成功能实用的CRM系统、进销存系统、生产ERP系统,实现对客户销售、供应商采购、产品物料、库存统计、生产监控等的精细化管理,直观强大的销售

    2022年5月11日
  • Android DeepLink介绍与使用

    Android DeepLink介绍与使用前段时间公司让调研一下DeepLink,说以后会用到,之前看了很久,并做了个demo,现整理一下,方便以后查阅,如果有幸帮助到其他人就更好了。基本概念DeepLink,又叫deeplinking,中文翻译作深层链接。简单地从用户体验来讲,DeepLink,就是可以让你在手机的浏览器/GoogleSearch上点击搜索的结果,便能直接跳转到已安装的应用中的某一个页面的技术。对于不…

    2022年6月18日
  • 什么是字符串常量池_常量池中的字符串是对象吗

    什么是字符串常量池_常量池中的字符串是对象吗关于字符串与字符串常量池JDK1.8-1.9,String底层从char数组变成了byte数组,原因是部分字符仅占一个byte,而堆中含有大量的String字符串,该优化能节省较多空间。StringTable为什么要调整(移入堆内)(JDK1.6-1.7)permSize默认比较小永久代垃圾回收频率低字符串拼接操作常量与常量的拼接结果在常量池,原理是编译器优化常量池中不会存在相同内容的常量只要其中一个是变量,结果就在堆中。变量拼接的原理是StringBuilder(final不算变量)

    2022年7月28日
  • nginx配置端口_修改redis端口

    nginx配置端口_修改redis端口sudosu#进入nginx自己的配置文件cd/etc/nginx/sites-enabledvimdefault#修改默认监听端口server{ listen80default_server; #这是nginx的端口,可修改 listen[::]:80default_server; #这是ipv6端口…

    2022年9月7日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号