Dropzone多张图片 上传问题 图片传不过来 uploadMultiple: false,传单张可以 求教?

清心如水 发布于 2016/08/24 18:33
阅读 837
收藏 0
<form  class="dropzone"  action="${ctx}/tabPackage/uploadBind/${tabPackage.packageid}" method="post" id="tabPackageImg" enctype="multipart/form-data">



Dropzone.options.tabPackageImg = {
//		autoProcessQueue: false,//自动上传
			maxFilesize: 5.0, // MB
			maxFiles: 3,//一次性上传的文件数量上限
			acceptedFiles: "image/*",
			thumbnailWidth: 300,
			thumbnailHeight: 300,
			addRemoveLinks: true,//添加移除文件
			dictDefaultMessage: "点击或拖拽上传图片",
			dictCancelUploadConfirmation: '你确定要取消上传吗?',
			dictMaxFilesExceeded: "您一次最多只能上传{{maxFiles}}个文件",
			dictFileTooBig: "文件过大({{filesize}}MB). 上传文件最大支持: {{maxFilesize}}MB.",
			dictResponseError: '文件上传失败!',
			dictInvalidFileType: "你不能上传该类型文件,文件类型只能是图片类型。",
			dictCancelUpload: "取消上传",
			dictRemoveFile: "重新上传",
			uploadMultiple: true,
			// Dropzone settings
			init: function () {
				var myDropzone = this;
//				this.element.querySelector("button[type=submit]").addEventListener("click", function (e) {
//					e.preventDefault();
//					e.stopPropagation();
//					myDropzone.processQueue();
//				});
				this.on("sendingmultiple", function () {
				});
				this.on("successmultiple", function (files, response) {
				});
				this.on("errormultiple", function (files, response) {
				});
			},



@RequestMapping(value = "uploadBind/{id}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public void upload2(@RequestParam("files") MultipartFile[] files, @PathVariable(value = "id") String id) throws IllegalStateException, IOException {
        TabPackage tabPackage = new TabPackage();
//        String[] img = {};
        String packageimages ="";
        for (int i = 0; i < files.length; i++) {
            String[] img = new String[3];
            if (!files[i].isEmpty()) {
                try {
                    String tempUrl = baseImageDir + "/" + "/packageBind/" + id + "/";
                    String filePath = tempUrl + files[i].getOriginalFilename();
                    File saveFile = new File(filePath);
                    if (!saveFile.exists()) {
                        saveFile.mkdirs();
                    }
                    // 转存文件
                    files[i].transferTo(saveFile);
                    tabPackage = tabPackageService.getById(id);
                    img[i] = "/packageBind/" + tabPackage.getPackageid() + "/" + files[i].getOriginalFilename() + ",";
                    packageimages=packageimages+img[i];
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        tabPackage.setPackageimages(packageimages);


        tabPackageService.update(tabPackage);



加载中
返回顶部
顶部