NutzCN Logo
问答 在做文件上传时遇到了一个问题后台始终接收不到文件,望指教
发布于 2664天前 作者 FWC1994 2363 次浏览 复制 上一个帖子 下一个帖子
标签:

后台代码是这样的
@At("/upLoadFiles")
@GET
@POST
@Ok("json")
@AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp" })
public String upLoadFiles(@Param("file") File file,@Param("build_id") Integer build_id,@Param("filetype") String filetype,@Param("filename") String filename){
return "";
}

前端代码是这样的
var formdata=new FormData();
formdata.append("file",file);
formdata.append("build_id",this.buildingData.attributes.objectid);
formdata.append("filetype",fileType);
formdata.append("filename",file.name);
var req = new XMLHttpRequest();
req.open("POST", "../client/service/comPetingDataController/upLoadFiles", true);
req.send(formdata);
调试发现其他的参数接收都正常,但是file对象却始终是null,可以保证前端file对象是正常的

5 回复

回复按钮旁边就是插入代码的按钮,把上面的代码重新发一遍

 @At("/upLoadFiles")
 @GET
 @POST
 @Ok("json")
 @AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp" })
 public String upLoadFiles(@Param("file") File file,@Param("build_id") Integer build_id,@Param("filetype") String filetype,@Param("filename") String filename){
 return "";
 }



 var formdata=new FormData();
 formdata.append("file",file);
 formdata.append("build_id",this.buildingData.attributes.objectid);
 formdata.append("filetype",fileType);
 formdata.append("filename",file.name);
 var req = new XMLHttpRequest();
 req.open("POST", "../client/service/comPetingDataController/upLoadFiles", true);
 req.send(formdata);

贴后台的解析日志

------WebKitFormBoundaryvaA7BLKK4DSB2523
2017-07-31 14:23:01 WARN [http-nio-0.0.0.0-8080-exec-13] Fail to find the firstBoundary (------WebKitFormBoundaryvaA7BLKK4DSB2523) in stream, quit!
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] Found mapping for [POST] path=/client/service/comPetingDataController/upLoadFiles : ComPetingDataController.upLoadFiles(...)
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] Get 'comPetingDataController'<class gisuni.lib.competing.controller.ComPetingDataController>
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] >> Load definition
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] Found IocObject(comPetingDataController) in IocLoader(AnnotationIocLoader@1337867464)
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] >> Make...'comPetingDataController'<class gisuni.lib.competing.controller.ComPetingDataController>
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] class gisuni.lib.competing.controller.ComPetingDataController , no config to enable AOP.
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] Get 'comPetingDataService'
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] Select Html4 Form upload parser --> /seedlandApp/client/service/comPetingDataController/upLoadFiles
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] FastUpload : /client/service/comPetingDataController/upLoadFiles
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] info created
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-10] Search mapping for path=/Competing/proxy : NOT Action match
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] Params map created - 3 params
2017-07-31 14:23:02 DEBUG [http-nio-0.0.0.0-8080-exec-16] boundary:
------WebKitFormBoundaryKDAmmBr3XcVBG2tA
2017-07-31 14:23:02 WARN [http-nio-0.0.0.0-8080-exec-16] Fail to find the firstBoundary (------WebKitFormBoundaryKDAmmBr3XcVBG2tA) in stream, quit!

你需要ajaxfileupload等js插件

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