NutzCN Logo
问答 使用webuploader 上传文件 后台接受不到参数
发布于 2445天前 作者 FWC1994 8732 次浏览 复制 上一个帖子 下一个帖子
标签:

前端代码如下

var uploader =WebUploader.create({
               		    swf: '../gistech/lib/fileUpload/Uploader.swf',
               		    server: 'CommonController/fileUpLoad',
               		    pick: {
               		    	id:"#picker",
               		    	innerHTML :"选择文件",
               		    	multiple:true
               		    },
               		    resize: false,
               		    accept:{
               		    	// extensions: 'jpg,jpeg,bmp,png,pdf,PDF',
               		    }
               		}); 
uploader.on('uploadBeforeSend',function(block,data){
       		    	   /*debugger
       		    	   var file = block.file;
       		    	   var fileName=encodeURIComponent(file.name);
       		    	   var downFlag=file.downFlag;
       		    	   data.downFlag=downFlag;
       		    	   data.fileName=fileName;*/
       		    	   var file = block.file;
       		    	   var obj=new Object();
     		    	   obj.fileName =file.name;
     		    	   obj.fileSize =file.size;
     		    	   obj.fileType =file.type;
     		    	   obj.fileFrom =that.fileFrom;
     		    	   obj.objectid =that.objectid;
     		    	   uploader.options.formData =obj;
     		    	   console.log( uploader.options.formData)
       		       }),

后台代码

@At("/fileUpLoad")
	@GET
	@POST
	@Ok("json")
	@AdaptBy(type = UploadAdaptor.class, args = { "ioc:myUpload" })
	public String fileUpLoad(@Param("file") File file,
						     @Param("fileName") String fileName,
							 @Param("fileSize") Integer fileSize,
							 @Param("fileType") String fileType,
							 @Param("fileFrom") String fileFrom,
							 @Param("objectid") Integer objectid) {
		JSONObject res = new JSONObject();
		try{
			String dataStr =  commonService.fileUpLoad(file,fileName,fileSize,fileType,fileFrom,objectid);
			res.put("success", true);
			res.put("data", dataStr);
			res.put("message", "上传文件成功");
		}catch (Exception e){
			e.printStackTrace();
			res.put("success", false);
			res.put("message", e.toString());
		}
		return res.toString();
    }

状况详细描述如下
查看前端network 发现表单webuploader提交的请求没有 request data 而是request payload,
比较奇怪 不知道是前端的问题还是后台配置的问题

6 回复

文件可以接收到 但是先要传的参数却获取不到

2018 03 07 15:55:15,826 DEBUG org.nutz.mvc.impl.UrlMappingImpl:87 - Found mapping for [POST] path=/CommonController/fileUpLoad : CommonController.fileUpLoad(...)
2018 03 07 15:55:15,832 DEBUG org.nutz.ioc.impl.NutIoc:143 - Get 'commonController'<class com.gisuni.sddc.controller.CommonController>
2018 03 07 15:55:15,832 DEBUG org.nutz.ioc.impl.NutIoc:165 - 	 >> Load definition
2018 03 07 15:55:15,834 DEBUG org.nutz.ioc.loader.combo.ComboIocLoader:120 - Found IocObject(commonController) in IocLoader(AnnotationIocLoader@1507411506)
2018 03 07 15:55:15,834 DEBUG org.nutz.ioc.impl.NutIoc:192 - 	 >> Make...'commonController'<class com.gisuni.sddc.controller.CommonController>
2018 03 07 15:55:15,836 DEBUG org.nutz.ioc.aop.impl.DefaultMirrorFactory:57 - class com.gisuni.sddc.controller.CommonController , no config to enable AOP.
2018 03 07 15:55:15,839 DEBUG org.nutz.ioc.impl.NutIoc:143 - Get 'commonService'<null>
2018 03 07 15:55:15,841 DEBUG org.nutz.mvc.upload.UploadAdaptor:177 - Select Html4 Form upload parser --> /seedland/CommonController/fileUpLoad
2018 03 07 15:55:15,843 DEBUG org.nutz.mvc.upload.FastUploading:38 - FastUpload : /CommonController/fileUpLoad
2018 03 07 15:55:15,845 DEBUG org.nutz.mvc.upload.FastUploading:53 - info created
2018 03 07 15:55:15,846 DEBUG org.nutz.mvc.upload.FastUploading:59 - Params map created - 0 params
2018 03 07 15:55:15,847 DEBUG org.nutz.mvc.upload.FastUploading:76 - boundary: 
------WebKitFormBoundaryk8mN5lBekEB7SgIq
2018 03 07 15:55:15,849 DEBUG org.nutz.mvc.upload.FastUploading:99 - skip first boundary
2018 03 07 15:55:15,850 DEBUG org.nutz.mvc.upload.FastUploading:110 - Reading...
2018 03 07 15:55:15,851 DEBUG org.nutz.mvc.upload.FastUploading:132 - Upload File info: FilePath=[null],fieldName=[id]
2018 03 07 15:55:15,851 DEBUG org.nutz.mvc.upload.FastUploading:212 - Found a param, name=[id] value=[WU_FILE_1]
2018 03 07 15:55:15,852 DEBUG org.nutz.mvc.upload.FastUploading:132 - Upload File info: FilePath=[null],fieldName=[name]
2018 03 07 15:55:15,853 DEBUG org.nutz.mvc.upload.FastUploading:212 - Found a param, name=[name] value=[zsblock.shp]
2018 03 07 15:55:15,854 DEBUG org.nutz.mvc.upload.FastUploading:132 - Upload File info: FilePath=[null],fieldName=[type]
2018 03 07 15:55:15,854 DEBUG org.nutz.mvc.upload.FastUploading:212 - Found a param, name=[type] value=[application/octet-stream]
2018 03 07 15:55:15,855 DEBUG org.nutz.mvc.upload.FastUploading:132 - Upload File info: FilePath=[null],fieldName=[lastModifiedDate]
2018 03 07 15:55:15,856 DEBUG org.nutz.mvc.upload.FastUploading:212 - Found a param, name=[lastModifiedDate] value=[Tue Oct 31 2017 16:01:40 GMT+0800 (中国标准时间)]
2018 03 07 15:55:15,857 DEBUG org.nutz.mvc.upload.FastUploading:132 - Upload File info: FilePath=[null],fieldName=[size]
2018 03 07 15:55:15,857 DEBUG org.nutz.mvc.upload.FastUploading:212 - Found a param, name=[size] value=[1132248]
2018 03 07 15:55:15,858 DEBUG org.nutz.mvc.upload.FastUploading:132 - Upload File info: FilePath=[zsblock.shp],fieldName=[file]
2018 03 07 15:55:15,859 DEBUG org.nutz.mvc.upload.FastUploading:136 - Upload Info: name=zsblock.shp,content_type=application/octet-stream
2018 03 07 15:55:15,932 DEBUG org.nutz.mvc.upload.FastUploading:228 - ...Done 1133017 bytes readed
null
null
null
null
null
---------------------获取----------------------

谢谢大佬 是我webuploader使用的问题 五体投地

大佬,我这也遇到了同样的问题,你是怎么解决的

添加回复
请先登陆
回到顶部