extjs multifile怎么限制extjs 上传文件类型型

Spring MultipartFile 文件上传【注解】& JQuery uploader plugin - paggywong - ITeye技术网站
首先准备工作:
我用的是Spring 3.02 +Gson1.71+JQuery 1.52+JQuery Uploader Plugin
applicationContext.xml:
&!-- 激活spring的注解. --&
&context:annotation-config /&
&!-- 扫描注解组件并且自动的注入spring beans中.
例如,他会扫描@Controller 和@Service下的文件.所以确保此base-package设置正确. --&
&context:component-scan base-package="com.swind.web" /&
&!-- 配置注解驱动的Spring MVC Controller 的编程模型.注:次标签只在 Servlet MVC工作! --&
&mvc:annotation-driven /&
dispatcher-servlet.xml
&bean id="multipartResolver" class="org.springframework.monsMultipartResolver"&
&property name="maxUploadSize"&
&value&&/value&
&/property&
&property name="maxInMemorySize"&
&value&4096&/value&
&/property&
&property name="defaultEncoding"&
&value&UTF-8&/value&
&/property&
&servlet-mapping&
&servlet-name&Dispatcher&/servlet-name&
&url-pattern&/&/url-pattern&
&/servlet-mapping&
服务端:Controller、Service都是从网上Copy来的,加以修改。
Controller:
为JQuery uploader 删除增加了一个handleDelete方法。
package com.swind.web.
import com.google.gson.G
import mon.GlobalV
import com.swind.web.model.FileM
import com.swind.web.service.UploadS
import java.io.IOE
import java.io.PrintW
import java.util.ArrayL
import java.util.I
import java.util.L
import javax.annotation.R
import javax.servlet.http.HttpServletR
import org.springframework.stereotype.C
import org.springframework.ui.M
import org.springframework.util.StringU
import org.springframework.web.bind.annotation.RequestM
import org.springframework.web.bind.annotation.RequestM
import org.springframework.web.bind.annotation.RequestP
import org.springframework.web.bind.annotation.ResponseB
import org.springframework.web.multipart.MultipartF
import org.springframework.web.multipart.support.DefaultMultipartHttpServletR
@Controller
public class UploadController {
@Resource(name = "uploadService")
private UploadService uploadS
* 描述 : &事先就知道确切的上传文件数目&. &br&
* @param file1
* @param file2
* @param model
* @throws IOException
@RequestMapping(value = "/upload.single", method = RequestMethod.POST)
@ResponseBody
String handleImport(
@RequestParam(value = "file", required = false) MultipartFile file,
HttpServletResponse response) throws IOException {
String uploadHome = GlobalVariable.getUploadHome();
FileModel fileModel = new FileModel();
if (file != null && StringUtils.hasText(file.getOriginalFilename())) {
System.out.println(file.getOriginalFilename());
fileModel.setName(file.getOriginalFilename());
fileModel.setSize(file.getSize());
fileModel.setType(file.getContentType());
String path = uploadService.saveFileToServer(file, uploadHome);
fileModel.setPath(path);
uploadService.json_encode(response, fileModel);
* 描述 : &事先就并不知道确切的上传文件数目,比如FancyUpload这样的多附件上传组件&. &br&
* @param model
* @param multipartRequest
* @throws IOException
@SuppressWarnings("unchecked")
@RequestMapping(value = "/upload.multi", method = RequestMethod.POST)
@ResponseBody
String handleImport(
DefaultMultipartHttpServletRequest multipartRequest,
HttpServletResponse response) throws IOException {
String uploadHome = GlobalVariable.getUploadHome();
List&FileModel& list = new ArrayList&FileModel&();
if (multipartRequest != null) {
Iterator iterator = multipartRequest.getFileNames();
while (iterator.hasNext()) {
MultipartFile multifile =
multipartRequest.getFile((String) iterator.next());
if (StringUtils.hasText(multifile.getOriginalFilename())) {
System.out.println(multifile.getOriginalFilename());
FileModel fileModel = new FileModel();
fileModel.setName(multifile.getOriginalFilename());
fileModel.setSize(multifile.getSize());
String path = uploadService.saveFileToServer(multifile, uploadHome);
fileModel.setPath(path);
list.add(fileModel);
uploadService.json_encode(response, list);
@RequestMapping(value = "/upload.*", method = RequestMethod.DELETE)
public @ResponseBody String handleDelete(@RequestParam(value = "file", required = false) String file,
HttpServletResponse response) throws IOException {
String uploadHome = GlobalVariable.getUploadHome();
boolean success = uploadService.deleteFiletoServer(file, uploadHome);
uploadService.json_encode(response, success);
Service:
package com.swind.web.
import com.google.gson.G
import java.io.F
import java.io.FileOutputS
import java.io.IOE
import java.io.InputS
import java.io.OutputS
import java.io.PrintW
import javax.servlet.http.HttpServletR
import org.springframework.stereotype.S
import org.springframework.web.multipart.MultipartF
@Service("uploadService")
public class UploadService {
* 描述 : &将文件保存到指定路径&. &br&
* @param multifile
* @param path
* @throws IOException
public String saveFileToServer(MultipartFile multifile, String path)
throws IOException {
// 创建目录
File dir = new File(path);
if (!dir.exists()) {
dir.mkdir();
// 读取文件流并保持在指定路径
InputStream inputStream = multifile.getInputStream();
OutputStream outputStream = new FileOutputStream(path
+ multifile.getOriginalFilename());
byte[] buffer = multifile.getBytes();
int bytesum = 0;
int byteread = 0;
while ((byteread = inputStream.read(buffer)) != -1) {
bytesum +=
outputStream.write(buffer, 0, byteread);
outputStream.flush();
outputStream.close();
inputStream.close();
return path + multifile.getOriginalFilename();
public boolean deleteFiletoServer(String file, String path)
throws IOException {
boolean success = Boolean.FALSE;
File f = new File(path+file);
if (f.exists()) {
f.delete();
success = Boolean.TRUE;
public void json_encode(final HttpServletResponse response, Object o) throws IOException{
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Gson gs = new Gson();
out.write(gs.toJson(o));
Bean:
package com.swind.web.
import java.io.S
public class FileModel implements Serializable {
private static final long serialVersionUID = 2381235L;
* @return the path
public String getPath() {
* @param path the path to set
public void setPath(String path) {
this.path =
* @return the name
public String getName() {
* @param name the name to set
public void setName(String name) {
this.name =
* @return the size
public long getSize() {
* @param size the size to set
public void setSize(long size) {
this.size =
public String getType() {
public void setType(String type) {
this.type =
HTML UPload Page:
&!DOCTYPE HTML&
* jQuery File Upload Plugin HTML Example 4.1.2
* /blueimp/jQuery-File-Upload
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
* Licensed under the MIT license:
* http://creativecommons.org/licenses/MIT/
&html lang="en" class="no-js"&
&meta charset="utf-8"&
&title&jQuery File Upload Example&/title&
&link rel="stylesheet" href="../res/css/themes/redmond/jquery-ui-1.8.1.custom.css" id="theme"&
&link rel="stylesheet" href="../res/css/jquery.fileupload-ui.css"&
&link rel="stylesheet" href="style.css"&
&div id="file_upload"&
&form action="/GuzzProject/upload.multi" method="POST" enctype="multipart/form-data"&
&input type="file" name="file" multiple&
&button type="submit"&Upload&/button&
&div class="file_upload_label"&上传文件&/div&
&table class="files"&
&tr class="file_upload_template" style="display:"&
&td class="file_upload_preview"&&/td&
&td class="file_name"&&/td&
&td class="file_size"&&/td&
&td class="file_upload_progress"&&div&&/div&&/td&
&td class="file_upload_start"&&button&开始&/button&&/td&
&td class="file_upload_cancel"&&button&取消&/button&&/td&
&tr class="file_download_template" style="display:"&
&td class="file_download_preview"&&/td&
&td class="file_name"&&a&&/a&&/td&
&td class="file_size"&&/td&
&td class="file_download_delete" colspan="3"&&button&删除&/button&&/td&
&div class="file_upload_overall_progress"&&div style="display:"&&/div&&/div&
&div class="file_upload_buttons"&
&button class="file_upload_start"&全部开始&/button&
&button class="file_upload_cancel"&全部结束&/button&
&button class="file_download_delete"&全部删除&/button&
&script src="../res/js/jquery-core/jquery-1.5.2.min.js"&&/script&
&script src="../res/js/jquery-ui/jquery-ui-1.8.1.custom.min.js"&&/script&
&script src="../res/js/plugin/uploader/jquery.fileupload.js"&&/script&
&script src="../res/js/plugin/uploader/jquery.fileupload-ui.js"&&/script&
&script src="../res/js/plugin/uploader/jquery.fileupload-uix.js"&&/script&
&script src="application.js"&&/script&
提供了静太部分的源文件下载,服务端的请自己写吧。
(131.6 KB)
下载次数: 360
浏览 11002
浏览: 64690 次
来自: 成都
非常感谢,虽然最终没有使用,但是的确学到东西了
果然解决了,好东西,大赞!!!!!!!!!
谢谢,今天遇到了这问题
请问将Spring Bean发布成WebService 如果s ...
你好,求源码参考,谢谢。邮箱常用软件推荐
原创软件推荐
MultiFilez是一个专门设计来同时编辑多个文件的软件,针对多文件的编辑处理动作,让你同时编辑多个文件的时候可以更顺手。
高速下载器地址
适合机型:三星Note4,三星Note4 ROM
Android版本:6.0.1
ROM大小:1370.00 MB
本站提供的软件会测试再上传,但无法保证所有软件都没有问题,如果您发现链接错误或其它问题,请在评论里告诉我们!
下载点支持点击下载(IE图标)或(迅雷图标),若直接点击下载速度太慢,请尝试点击其他的下载点,若文件太大请使用高速下载器。为确保下载的文件能正常使用,请使用最新版本解压本站软件。
建议大家谨慎对待所下载的文件,大家在安装的时候务必留意每一步!关于或的有关提示,请自行注意选择操作。
本站所有资源均是软件作者、开发商投稿、网上搜集,任何涉及商业盈利目的均不得使用,否则产生的一切后果将由您自己承担!将不对任何资源负法律责任。所有资源请在下载后24小时内删除。君,已阅读到文档的结尾了呢~~
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
利用VC%2b%2b管理多种类型文件的方法
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer--144.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口extjs - How to get Sencha file upload field to accept multiple files - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 7.1 million programmers, just like you, helping each other.
J it only takes a minute:
I have Sencha Ext JS application where I use File form field (Ext.form.field.File) to upload files. It's working fine, but I want users to be able to select multiple files for upload at once, like , for example. I have another, non-Sencha site (in which I had direct control over HTML) where I solved this problem by using multiple attribute of the INPUT element:
&input type="file" name="files" multiple&
Sencha, however, doesn't support multiple files in file upload field natively, at least as of current version (4.1). Perhaps it's possible to alter HTML output emitted by Sencha for &input& element, but I am not sure how.
You can create a xtype:
Ext.define('fileupload',{
extend: 'Ext.form.field.Text'
,alias: 'widget.fileupload'
,inputType: 'file'
,listeners: {
render: function (me, eOpts) {
var el = Ext.get(me.id+'-inputEl');
size: me.inputSize || 1
if(me.multiple) {
multiple: 'multiple'
And use it in your form:
,items: [{
xtype: 'fileupload'
,vtype: 'file'
,multiple: true // multiupload (multiple attr)
,acceptMimes: ['doc', 'xls', 'xlsx', 'pdf', 'zip', 'rar'] // file types
,acceptSize: 2048
,fieldLabel: 'File &span class="gray"&(doc, xls, xlsx, pdf, zip, 2 MB max)&/span&'
,inputSize: 76 // size attr
,msgTarget: 'under'
,name: 'filesToUpload[]'
See example on
There is a plugin for this maybe you can use it:
1,99462140
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .25906
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 extjs 上传文件类型 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信