element-ui上传组件el-upload还是不行,报错:java.io.IOException: Corrupt form data: premature ending
请问那个大佬会解决,能否发发前端代码参考一下?(已解决)
1、更新升级:
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal-undertow</artifactId>
<version>3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jfinal/jfinal -->
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
<version>5.0.8</version>
</dependency>
2、el-upload 加一个 name属性
vue代码:
<el-upload action="/admin/imgUpload" accept="image/jpeg,image/jpg,image/png" multiple list-type="picture-card" :file-list="fileImgList" :on-success="handleSuccess" :on-remove="handleRemove"> <i class="el-icon-plus"></i> </el-upload> <el-dialog :visible.sync="bigImgVisible"> <img style="width:100%;" :src="dialogImageUrl" alt=""> </el-dialog> <el-dialog :visible.sync="dialogVisible"> <img width="100%" :src="dialogImageUrl" alt=""> </el-dialog> 属性: dialogImageUrl: null,//预览图片的地址 bigImgVisible: false,//预览图片是否展示 fileImgList: [],//上传的图片集合 eqForm:{ imageUrl:'',//图片路径的拼接,是使用.逗号拼接成的字符串 }, //图片上传 //dialogImageUrl: '', dialogVisible: false, disabled: false, //图片上传end 方法: uploadFile(params){ const file = params.file, fileType = file.type, isImage = fileType.indexOf("image") != -1, isLt2M = file.size / 1024 / 1024 < 2; // 这里常规检验,看项目需求而定 if (!isImage) { this.$message.error("只能上传图片格式png、jpg、gif!"); return; } if (!isLt2M) { this.$message.error("只能上传图片大小小于2M"); return; } // 根据后台需求数据格式 const form = new FormData(); // 文件对象 form.append("file", file); // 本例子主要要在请求时添加特定属性,所以要用自己方法覆盖默认的action form.append("enctype", 'multipart/form-data');//enctype="multipart/form-data" // 项目封装的请求方法,下面做简单介绍 this.$axios({ method: 'POST', url: '/admin/imgUpload', headers: {"content-type": "multipart/form-data"}, data: form }).then((response) => { //这里使用了ES6的语法 if (response.status === 200) { console.log(response) } }).catch((error) => { console.log(error) }); }, //图片的预览方法: onPreview(file){ if (file.url) { this.dialogImageUrl = file.url; this.bigImgVisible = true; } }, //图片的删除方法 handleRemove(file, fileList) { //注意图片删除时,会改变图片的Url格式,但是不影响具体的使用。 this.fileImgList = fileList; }, //图片上传成功的回调 handleSuccess(response, file, fileList) { this.fileImgList = fileList; }, //执行提交图片拼接字段的方法 submitImg(){ //在执行此方法时,可以对图片的路径进行拼接,最终拿到想要的数据 if (this.fileImgList && this.fileImgList.length) { this.eqForm.imageUrl = ''; this.fileImgList.forEach((file, fIndex) => { if (fIndex != this.fileImgList.length - 1) { this.eqForm.imageUrl += file.url + ','; } else { this.eqForm.imageUrl += file.url; } }) } },
报错:
java.lang.RuntimeException: java.io.IOException: Corrupt form data: premature ending at com.jfinal.upload.MultipartRequest.wrapMultipartRequest(MultipartRequest.java:126) at com.jfinal.upload.MultipartRequest.<init>(MultipartRequest.java:58) at com.jfinal.core.Controller.getFiles(Controller.java:872) at com.jfinal.core.Controller.getFile(Controller.java:877) at com.l2qq.qiniu.ImgUploadController.index(ImgUploadController.java:13) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578) at com.jfinal.aop.Invocation.invoke(Invocation.java:97) at com.jfinal.admin.auth.AdminAuthInterceptor.intercept(AdminAuthInterceptor.java:50) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.jfinal.admin.auth.IsInitialPwInterceptor.intercept(IsInitialPwInterceptor.java:17) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.jfinal.admin.common.CommonLogInterceptor.intercept(CommonLogInterceptor.java:45) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.jfinal.admin.login.LoginSessionInterceptor.intercept(LoginSessionInterceptor.java:59) at com.jfinal.aop.Invocation.invoke(Invocation.java:91) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:110) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:90) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:275) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:79) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:134) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:131) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:255) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:79) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:100) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:852) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2019) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1558) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1449) at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280) at java.base/java.lang.Thread.run(Thread.java:1589) Caused by: java.io.IOException: Corrupt form data: premature ending at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:207) at com.oreilly.servlet.MultipartRequest.parse(MultipartRequest.java:242) at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:180) at com.jfinal.upload.MultipartRequest.wrapMultipartRequest(MultipartRequest.java:107) ... 53 more
《el-upload
:action="actionUrl"
:headers="headers"
:class="form.businessLicenseFile ? 'hide':''"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-success="handleSuccess"
:on-remove="handleRemove"
accept="image/jpg,image/jpeg,image/png"
:before-upload="beforeUpload"
:file-list="businessLicenseList"
》
注意看上面的 :action="actionUrl"
其中的 actionUrl 数据如下:
export default {
data() {
return {
actionUrl: process.env.VUE_APP_BASE_API + '/system/upload?type=customer',
....
}
}
}