onevcat / Kingfisher

A lightweight, pure-Swift library for downloading and caching images from the web.
MIT License
23.13k stars 2.64k forks source link

约定的图片地址实际资源为视频时,在列表中加载这种资源,内存激增导致 App 闪退。 #2221

Open liyunxin opened 6 months ago

liyunxin commented 6 months ago

喵神大佬,希望可以指点一下,在事先无法知道资源的类型,在KF里面有判断到资源为视频不是图片的时候直接返回 placeholder 的方法吗?

onevcat commented 6 months ago

无论如何都是需要发生一次HTTP请求的。Kingfisher并没有预先检查这些,所以需要自己实现一下。如果你的server端实现正确的话,可以向资源URI发一个HEAD请求,通过检查header 的 content type来判断到底是视频还是图片(当然,前提是你的server返回的这个值是正确的),然后再决定后续使用 Kingfisher 的方式和逻辑。

onevcat commented 6 months ago

TASK: Consider to add a header check when receiving the first data chunk (or header). Early fails with an error if the expected type cannot be handled.