NutzCN Logo
问答 第一次微信下载二维码后,小程序<image/>提示404,重新访问又可以了
发布于 1479天前 作者 天空 1367 次浏览 复制 上一个帖子 下一个帖子
标签:
//JAVA端,从流写到文件
String path = AzUpLoadConstants.UP_BOOKORDER_QRCODE_URL + order.getShopId() + "/"  + String.valueOf(billNo);
File f = new File(Mvcs.getServletContext().getRealPath(path + "/1.png"));
Files.write(f, ar.getInputStream());
//返回路径JSON
return  path + "/1.png";

第一次前端报错404

VM1344:1 Failed to load image http://localhost:8080/test/qrcode/1/BK1-2003110001/1.png?v=0.8105500422015619
the server responded with a status of 404 (HTTP/1.1 404) 
From server ::1

微信小程序的Headers

Request URL: http://localhost:8080/test/qrcode/1/BK1-2003110001/1.png?v=0.8105500422015619
Request Method: GET
Status Code: 404 
Remote Address: [::1]:8080
Referrer Policy: no-referrer-when-downgrade

Content-Language: zh-CN
Content-Length: 1110
Content-Type: text/html;charset=utf-8
Date: Wed, 11 Mar 2020 08:30:53 GMT
X-Powered-By: nutz/1.r.68.v20190329 <nutzam.com>
Accept: image/webp,image/apng,image/*,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Host: localhost:8080
Referer: https://servicewechat.com/wx1933d256f98883c7/devtools/page-frame.html
Sec-Fetch-Dest: image
Sec-Fetch-Site: cross-site
Sec-Fetch-User: ?F
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.02.1911180 MicroMessenger/7.0.4 Language/zh_CN webview/42 miniprogram port/50506 token/728d74aad8322102cd6c3a623b130414

但这时在浏览器访问图片网址:http://localhost:8080/test/qrcode/bookorder/1/BK1-2003110001/1.png?v=0.8105500422015619
是可以访问到图片的。
难道Files.write()写完文件,还没有刷新导致前端404吗?
请大神解析一下,谢谢

2 回复

不要写到content path下,否则tomcat一重启就删掉了

@wendal 先谢谢!
本地开发时,重新发布项目时是会删除。
但现在不是这个原因,现在是在Action里第一次访问时,在ContextPath下生成这个目录和二维码图片。返回图片URL到前端小程序,但前端马上访问第一次生成的图片失败(404),但如果在小程序加:

setTimeOut({
改<image/>的src
},5)

就可以显示,不延时就404,有点郁闷的是Files.write()已经完了,前端也访问不了图片文件吗?

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