问题点: 在 iOS 手机微信里打开网页,点击下载视频,下载的视频不能识别文件名和文件大小,求解决。 https://www.solaredufn.com/upload/download/Untitled-2.html
![]() | 1 hua123s 2022-11-30 15:27:44 +08:00 用小程序做吧 https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html 微信环境网页好像不支持吧(...) |
![]() | 2 Jasio 2022-11-30 15:42:23 +08:00 服务端添加相应头试试 https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Disposition ``` http http://192.168.50.181:3000/56954.mp4 HTTP/1.1 200 OK Accept-Ranges: bytes Connection: keep-alive Content-Disposition: inline; filename="56954.mp4" Content-Length: 20612729 Content-Type: video/mp4 Date: Wed, 30 Nov 2022 07:39:42 GMT ETag: "7653bb231212bafb00a5b51d37effe4e26563973" Keep-Alive: timeout=5 ``` |
![]() | 3 hua123s 2022-11-30 15:57:11 +08:00 收回刚才的话,试了下是可以的。 res.header('Content-Type', 'application/octet-stream'); res.header('Content-Disposition', 'attachment; filename=video.mp4'); 主要是这两个 header 就可以了。 |
![]() | 4 hua123s 2022-11-30 16:01:07 +08:00 |
![]() | 7 wangsongyan 2022-11-30 16:08:35 +08:00 ![]() |
![]() | 9 hua123s 2022-11-30 17:03:24 +08:00 如果你有 nginx 可以这样。 server 外层加 map $uri $basename { ~/(?<captured_basename>[^/]*)$ $captured_basename; } 具体的 location pattern 加 add_header Content-Disposition "attachment; filename=$basename"; add_header Content-Type "application/octet-stream"; 完事 |
![]() | 10 zhangdashuan 2022-12-01 09:47:44 +08:00 前端时间碰到一个问题,返回.zip 格式字节流,页面下载下来打不开,名称不对,也没有后缀名。后来发现是被转码了。后端设置请求头中名称需要 encode 一下,前端获取后需要 decode 一下。不知道对你有没有帮助。 |
![]() | 11 coffeeing OP @hua123s 昨晚后端写了,我测试下来没有解决大小和文件名,再麻烦看下是这样写么? location / { if (!-e $request_filename){ rewrite “(.*)$ /index.php?s-$1 last;break; add header Content-Disposition "attachment; filename=$basename" add header Content-Type "application/octet-stream"; } } map $uri $basename { ~/(?<captured basename>[~/]*)$ $captured basename; } server { listen 80: |
![]() | 12 coffeeing OP @zhangdashuan 麻烦有没有对应的代码贴下,我学习下,谢谢谢谢 |
![]() | 13 hua123s 2022-12-01 10:23:14 +08:00 |
![]() | 14 coffeeing OP 我加了对应的服务端配置代码,打开下载是这样,文件没有识别出来,文件大小是 0B ,选择用其他应用打开看到的文件名是这样: https___www.solaredufn.com_upload_download_56954 <img decoding="async" src=" ![]() |
![]() | 15 wangsongyan 2022-12-01 11:45:15 +08:00 @coffeeing #14 加我:cXE6MTEwNDIzNzUzNA==(base64) |
![]() | 16 coffeeing OP @wangsongyan 加了,非常感谢 |