NutzCN Logo
问答 linux虚拟主机 项目上传图片 404
发布于 2969天前 作者 CHQ 1767 次浏览 复制 上一个帖子 下一个帖子
标签:
2016-09-29 23:30:06,910 org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:183) DEBUG - Select Html4 Form upload parser --> /ueditor/bd/uploadimage
2016-09-29 23:30:06,911 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:39) DEBUG - FastUpload : /ueditor/bd/uploadimage
2016-09-29 23:30:06,911 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:54) DEBUG - info created
2016-09-29 23:30:06,912 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:60) DEBUG - Params map created - 0 params
2016-09-29 23:30:06,913 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:77) DEBUG - boundary: 
------WebKitFormBoundarySbDqa0bAziBRsyAQ
2016-09-29 23:30:07,035 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:100) DEBUG - skip first boundary
2016-09-29 23:30:07,036 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:111) DEBUG - Reading...
2016-09-29 23:30:07,037 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:133) DEBUG - Upload File info: FilePath=[97N58PICFK8_1024.jpg],fieldName=[Filedata]
2016-09-29 23:30:07,038 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:137) DEBUG - Upload Info: name=97N58PICFK8_1024.jpg,content_type=image/jpeg
2016-09-29 23:30:07,154 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:231) DEBUG - ...Done 114123 bytes readed
2016-09-29 23:30:07,157 com.yunou.mvc.LogTimeProcessor.process(LogTimeProcessor.java:24) DEBUG - [POST]URI=/ueditor/bd/uploadimage 254ms
2016-09-29 23:31:03,081 org.nutz.mvc.impl.ActionInvoker.getActionChain(ActionInvoker.java:87) DEBUG - Path=[/upload/image/] available methods[POST] but request [GET], using the wrong http method?
2016-09-29 23:31:03,082 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:110) DEBUG - Search mapping for path=/upload/image/ : NOT Action match
2016-09-30 07:57:59,483 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [GET] path=/robots : IndexModule.news(IndexModule.java:61)
2016-09-30 07:57:59,484 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'siteService'<class com.yunou.services.SiteService>
2016-09-30 07:57:59,626 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM t_site  WHERE id=?
方法
    @AdaptBy(type = UploadAdaptor.class, args = {"ioc:imageUpload"})
    @POST
    @At
    @Ok("json")
    //AdaptorErrorContext必须是最后一个参数
    public Object image(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
        try {
            if (err != null && err.getAdaptorErr() != null) {
                return Result.error(1,"upload.notvalid");
            } else if (tf == null) {
                return Result.error("upload.empty");
            } else {
                String p = Globals.AppRoot;
                String f = Globals.AppUploadPath + "/image/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
                Files.write(new File(p + f), tf.getInputStream());
                return Result.success("upload.success", Globals.AppBase+f);
            }
        } catch (Exception e) {
            return Result.error("system.err");
        } catch (Throwable e) {
            return Result.error("upload.formaterror");
        }
    }

$('#file_upload').uploadifive({ 'auto': true, 'multi': false, 'width': '100%', 'height': '35', 'buttonText': '请选择图片', 'fileType': 'image/*', 'fileSizeLimit': 1024, 'queueSizeLimit': 1, 'formData': {}, 'queueID': 'queue', 'uploadScript': '${base}/upload/image', 'onUploadComplete': function (file, data) { data = JSON.parse(data); if (data.code == 0) { toastr.success(data.msg); $("#img").html("<img src='" + data.data + "' style='width:150px;height:95px;'>"); $("#picurl").val(data.data); } else { clearFile(); toastr.error(data.msg); } }, 'onDrop': function (file, fileDropCount) { clearFile(); }, 'onClearQueue': function (queue) { clearFile(); }, 'onCancel': function () { clearFile(); } });
6 回复

发了两个请求? /ueditor/bd/uploadimage 哪里来的?

@IocBean
@At("/upload")
public class UploadModule {
	private static final Log log = Logs.get();

	@AdaptBy(type = UploadAdaptor.class, args = {"ioc:imageUpload"})
    @POST
    @At
    @Ok("json")
    //AdaptorErrorContext必须是最后一个参数
    public Object image(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
        try {
            if (err != null && err.getAdaptorErr() != null) {
                return Result.error(1,"upload.notvalid");
            } else if (tf == null) {
                return Result.error("upload.empty");
            } else {
                String p = Globals.AppRoot;
                String f = Globals.AppUploadPath + "/image/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
                Files.write(new File(p + f), tf.getInputStream());
                return Result.success("upload.success", Globals.AppBase+f);
            }
        } catch (Exception e) {
            return Result.error("system.err");
        } catch (Throwable e) {
            return Result.error("upload.formaterror");
        }
    }
	
	@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
    @POST
    @At
    @Ok("json")
    //AdaptorErrorContext必须是最后一个参数
    public Object file(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
		 NutMap nutMap = new NutMap();
        try {
            if (err != null && err.getAdaptorErr() != null) {
                return nutMap.addv("state", Result.error(1,"upload.notvalid"));
            } else if (tf == null) {
                return nutMap.addv("state", Result.error("upload.empty"));
            } else {
                String p = Globals.AppRoot;
                String f = Globals.AppUploadPath + "/file/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
                Files.write(new File(p + f), tf.getInputStream());
                nutMap.addv("state", Result.success("upload.success", Globals.AppBase+f));
                nutMap.addv("original", tf.getSubmittedFileName());
                nutMap.addv("type", tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf(".") + 1));
                nutMap.addv("size", tf.getSize());
                return nutMap;
            }
        } catch (Exception e) {
            return nutMap.addv("state", Result.error("system.err"));
        } catch (Throwable e) {
            return nutMap.addv("state", Result.error("system.err"));
        }
    }
	
}

百度编辑器的 使用NutzWk的案例

上条复制错了

@IocBean
@At("/ueditor/bd")
public class UeditorModule {
    @At
    @Ok("json")
    public Object index(@Param("action") String action, HttpServletRequest req) {
        return Json.fromJson(Files.read(Globals.AppRoot + "/assets/admin/libs/ueditor/nutz/config.json").replace("$base", Globals.AppBase));
    }

    @AdaptBy(type = UploadAdaptor.class, args = {"ioc:imageUpload"})
    @POST
    @At
    @Ok("json")
    //AdaptorErrorContext必须是最后一个参数
    public Object uploadimage(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
        NutMap nutMap = new NutMap();
        try {
            if (err != null && err.getAdaptorErr() != null) {
                return nutMap.addv("state", "FAIL");
            } else if (tf == null) {
                return nutMap.addv("state", "FAIL");
            } else {
                String p = Globals.AppRoot;
                String f = Globals.AppUploadPath + "/image/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
                Files.write(new File(p + f), tf.getInputStream());
                nutMap.addv("state", "SUCCESS");
                nutMap.addv("url", Globals.AppBase + f);
                nutMap.addv("original", tf.getSubmittedFileName());
                nutMap.addv("type", tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf(".") + 1));
                nutMap.addv("size", tf.getSize());
                return nutMap;
            }
        } catch (Exception e) {
            return nutMap.addv("state", "FAIL");
        } catch (Throwable e) {
            return nutMap.addv("state", "FAIL");
        }
    }

    @AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
    @POST
    @At
    @Ok("json")
    public Object uploadfile(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
        NutMap nutMap = new NutMap();
        try {
            if (err != null && err.getAdaptorErr() != null) {
                return nutMap.addv("state", "FAIL");
            } else if (tf == null) {
                return nutMap.addv("state", "FAIL");
            } else {
                String p = Globals.AppRoot;
                String f = Globals.AppUploadPath + "/file/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
                Files.write(new File(p + f), tf.getInputStream());
                nutMap.addv("state", "SUCCESS");
                nutMap.addv("url", Globals.AppBase + f);
                nutMap.addv("original", tf.getSubmittedFileName());
                nutMap.addv("type", tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf(".") + 1));
                nutMap.addv("size", tf.getSize());
                return nutMap;
            }
        } catch (Exception e) {
            return nutMap.addv("state", "FAIL");
        } catch (Throwable e) {
            return nutMap.addv("state", "FAIL");
        }
    }

    @AdaptBy(type = UploadAdaptor.class, args = {"ioc:videoUpload"})
    @POST
    @At
    @Ok("json")
    public Object uploadvideo(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
        NutMap nutMap = new NutMap();
        try {
            if (err != null && err.getAdaptorErr() != null) {
                return nutMap.addv("state", "FAIL");
            } else if (tf == null) {
                return nutMap.addv("state", "FAIL");
            } else {
                String p = Globals.AppRoot;
                String f = Globals.AppUploadPath + "/video/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
                Files.write(new File(p + f), tf.getInputStream());
                nutMap.addv("state", "SUCCESS");
                nutMap.addv("url", Globals.AppBase + f);
                nutMap.addv("original", tf.getSubmittedFileName());
                nutMap.addv("type", tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf(".") + 1));
                nutMap.addv("size", tf.getSize());
                return nutMap;
            }
        } catch (Exception e) {
            return nutMap.addv("state", "FAIL");
        } catch (Throwable e) {
            return nutMap.addv("state", "FAIL");
        }
    }
}

没看懂

来自炫酷的 NutzCN

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