NutzCN Logo
问答 微信小程序上传多个图片,后台nutz 接口如何处理?
发布于 426天前 作者 qq_e3b6dba3 632 次浏览 复制 上一个帖子 下一个帖子
标签:

微信小程序上传多个图片,后台nutz 接口如何处理?各位有代码例子借鉴下

15 回复

跟普通网页没啥两样

@At("/addstandby/?")
	@Ok("json")
	@AdaptBy(type = UploadAdaptor.class, args = { "ioc:myUpload" })
	public Object addstandby(String type, @Param("..") Tbl_ad_plan plan,
			@Param("ad_area_desc") String area_desc,
			@Param("price_info") String price_info,
			@Param("charge_ad_fee") Integer charge_ad_fee,
			@Param("fee_way") Integer fee_way,
			@Param("period_month") Integer period_month,
			@Param("gift_month") Integer gift_month,
			@Param("pic_url") String pic_url, @Param("pic") List<TempFile> tf,
			@Param("ad_content") String title, HttpServletRequest req) {

这是之前写的网页接收前台传多个图片接口参数方法

@wendal 微信服务的后台接口也是这样写,可以不?

微信平台?啥意思啊?联系不起来啊呀

业务需求,有个微信的后台服务,有个平台服务后台

现在要小程序端上传图片到服务器上

@wendal tf的值为: [http://tmp/wx4d085de7edcb57bc.o6zAJs6zWZCBOcvUS7LH85jBNrA0.FdQstf2zwznycfb27073e4ef7f06f99b49c8cff86757.jpg],后台提示错误如下:
2018-08-19 16:19:39> [org.nutz.mvc.impl.processor.FailProcessor] - Erro@/celltest/addpicture :
java.lang.ClassCastException: java.lang.String cannot be cast to org.nutz.mvc.upload.TempFile
at com.ruyima.eop.controller.business.CelltestModule.addpicture(CelltestModule.java:173)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:22)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:99)
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:40)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:64)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:94)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.ruyima.eop.controller.business.WebCrossOriginFilter.doFilter(WebCrossOriginFilter.java:86)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

那位在给看看

当表单传过了,并非文件上传

upload: function (page, path) {
var that = this;
var curImgList = [];
for (var i = 0; i < path.length; i++) {
wx.showToast({
icon: "loading",
title: "正在上传"
}),
wx.uploadFile({
url: main_url + '/eop/celltest/addpicture',//接口处理在下面有写
filePath: path[i].pic,
name: 'file',
header: { "Content-Type": "multipart/form-data" },
formData: { pic: pathpath[i]},

这是微信小程序前端js

有 插入代码 按钮呀,为啥都选择无视呢

你的后端写的是

@Param("pic_url") String pic_url,
@Param("pic") List<TempFile> tf

微信小程序要这样对应

wx.uploadFile({
    url: main_url + '/eop/celltest/addpicture',//接口处理在下面有写
    filePath: path[i], // 为啥你要加.pic,明显不对呀
    name: 'pic', // 这里对应的字符串就是文件对应的表单名
    header: { "Content-Type": "multipart/form-data" },
    formData: { pic_path: path[i] } // pic_path才是路径,原本写的是pic
}
添加回复
请先登陆
回到顶部