NutzCN Logo
问答 @Param("img") TempFile tf 接收不到传过来的文件
发布于 2558天前 作者 wx_l0asj2fqeg0jtrr696ah 1668 次浏览 复制 上一个帖子 下一个帖子
标签:
//这是发送代码
        	 Request req = Request.create(url,METHOD.POST);
					req.getParams().put("name", params.get("name"));
					req.getParams().put("project", params.get("project"));
					req.getParams().put("version", params.get("version"));
					req.getParams().put("mark", params.get("mark"));
					req.getParams().put("img", (File)params.get("img"));
//					req.getParams().put("m", m);
					FilePostSender sender = new FilePostSender(req);
					Response resp = sender.send();
// 这是接收代码
	@At("/jnccoss/img/upload/add")
	@AdaptBy(type = UploadAdaptor.class, args = { "ioc:imageUpload" })
	@Ok("json")
	@POST
	public Object uploadImg(Map m, String project, String name, String version, boolean mark, @Param("img") TempFile tf,
			AdaptorErrorContext err) {}

如果 req.getParams().put("img", (File)params.get("img")); 注释掉是可以接收到其它的参数的。如果不注释掉,所有参数都接收不到。
不知道 是不是传的文件格式 不对

18 回复

img 原是 MultipartFile file 类型 转成了File

贴一下日志

--------FormBoundary6vbs3mdlecg0bqajju26praacc
[DEBUG] 2017-11-14 10:44:48,490 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:100) - skip first boundary
[DEBUG] 2017-11-14 10:44:48,490 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:111) - Reading...
[DEBUG] 2017-11-14 10:44:48,491 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:133) - Upload File info: FilePath=[upload_bceeddde_c0b9_49f3_83d9_e14d3ae8933c_00000000.tmp],fieldName=[img]
[DEBUG] 2017-11-14 10:44:48,491 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:137) - Upload Info: name=upload_bceeddde_c0b9_49f3_83d9_e14d3ae8933c_00000000.tmp,content_type=application/octet-stream
[INFO ] 2017-11-14 10:44:48,492 org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:229) - Adapter Error catched , but I found AdaptorErrorContext param, so, set it to args, and continue
org.nutz.mvc.upload.UploadUnsupportedFileNameException: Unsupport file name 'upload_bceeddde_c0b9_49f3_83d9_e14d3ae8933c_00000000.tmp' 
	at org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:140)
	at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:186)
	at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:62)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:224)
	at org.nutz.mvc.upload.UploadAdaptor.adapt(UploadAdaptor.java:117)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

你限制了文件后缀哦

这应该怎么修改呢?

到upload.js里面看看允许什么后缀,然后把tmp后缀加上

后缀加上了,但好像不是这里的问题,我都换成jpg图片了,但是还是报这个错误,还是这个文件名?难道还有缓存不成?

发现了。是发送端有问题,我再找找看

tmp后缀加上了,但是还是会报这个错误

tmp加进去了

uploadFileContext : {
        type : 'org.nutz.mvc.upload.UploadingContext',
        singleton : false,
        args : [ { refer : 'tmpFilePool' } ],
        fields : {
            // 是否忽略空文件, 默认为 false
            ignoreNull : true,
            // 单个文件最大尺寸(大约的值,单位为字节,即 20971520 为 20M)
            maxFileSize : 20971520,
            // 正则表达式匹配可以支持的文件名
            nameFilter : '^(.+[.])(tmp|jepg|gif|jpg|png|doc|docx|xls|xlsx|rar|zip|7z|flv|swf|mkv|avi|txt|xml|pdf|md|pptx|ppt|flv|swf|mkv|avi|rm|rmvb|wmv|mp4|mov|mpg|mpeg|class|jar)$'
        }
    },

贴当前报错信息

就是上面的呀,最新的了

重新贴一下呗, 然后debug一下FastUploading的140行看看

我感觉是你没改对upload.js吧

这是最新的日志

[DEBUG] 2017-11-14 13:21:43,198 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [POST] path=/jnccoss/img/upload/add : UploadModule.uploadImg(UploadModule.java:33)
[DEBUG] 2017-11-14 13:21:43,201 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'uploadModule'<class org.clso.oss.modules.UploadModule>
[DEBUG] 2017-11-14 13:21:43,202 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) - 	 >> Load definition name=uploadModule
[DEBUG] 2017-11-14 13:21:43,204 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) - Found IocObject(uploadModule) in AnnotationIocLoader(packages=[org.clso.oss.modules])
[DEBUG] 2017-11-14 13:21:43,204 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) - 	 >> Make...'uploadModule'<class org.clso.oss.modules.UploadModule>
[DEBUG] 2017-11-14 13:21:43,205 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) - Load class org.clso.oss.modules.UploadModule without AOP
[DEBUG] 2017-11-14 13:21:43,205 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) - Save object 'uploadModule' to [app] 
[DEBUG] 2017-11-14 13:21:43,227 org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:184) - Select Html4 Form upload parser --> /img-manage/jnccoss/img/upload/add
[DEBUG] 2017-11-14 13:21:43,232 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:39) - FastUpload : /jnccoss/img/upload/add
[DEBUG] 2017-11-14 13:21:43,234 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:54) - info created
[DEBUG] 2017-11-14 13:21:43,234 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:60) - Params map created - 0 params
[DEBUG] 2017-11-14 13:21:43,236 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:77) - boundary: 
--------FormBoundary4638u9hujsidkqd4nthhm5i1a8
[DEBUG] 2017-11-14 13:21:43,241 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:100) - skip first boundary
[DEBUG] 2017-11-14 13:21:43,241 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:111) - Reading...
[DEBUG] 2017-11-14 13:21:43,242 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:133) - Upload File info: FilePath=[upload_bceeddde_c0b9_49f3_83d9_e14d3ae8933c_00000008.tmp],fieldName=[img]
[DEBUG] 2017-11-14 13:21:43,243 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:137) - Upload Info: name=upload_bceeddde_c0b9_49f3_83d9_e14d3ae8933c_00000008.tmp,content_type=application/octet-stream
[INFO ] 2017-11-14 13:21:43,244 org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:229) - Adapter Error catched , but I found AdaptorErrorContext param, so, set it to args, and continue
org.nutz.mvc.upload.UploadUnsupportedFileNameException: Unsupport file name 'upload_bceeddde_c0b9_49f3_83d9_e14d3ae8933c_00000008.tmp' 
	at org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:140)
	at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:186)
	at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:62)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:224)
	at org.nutz.mvc.upload.UploadAdaptor.adapt(UploadAdaptor.java:117)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

这是引用类,并没有你说的那个FastUploading呀

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.nutz.img.Images;
import org.nutz.lang.Files;
import org.nutz.lang.OS;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.impl.AdaptorErrorContext;
import org.nutz.mvc.upload.FieldMeta;
import org.nutz.mvc.upload.TempFile;
import org.nutz.mvc.upload.UploadAdaptor;

这是第140左右的代码

   // 作为文件读取
                if (meta.isFile()) {
                    if (log.isDebugEnabled())
                        log.debugf("Upload Info: name=%s,content_type=%s", meta.getFileLocalName(),meta.getContentType());
                    // 检查是否通过文件名过滤
                    if (!context.isNameAccepted(meta.getFileLocalName())) {
                        throw new UploadUnsupportedFileNameException(meta);
                    }
                    // 检查是否通过文件类型过滤
                    if (!context.isContentTypeAccepted(meta.getContentType())) {
                        throw new UploadUnsupportedFileTypeException(meta);
                    }



就是debug一下context.isNameAccepted看看

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