即使 url 返回 301 状态,如何使用 Glide 加载图像?

发布于 2025-01-14 22:18:47 字数 926 浏览 3 评论 0原文

我正在尝试使用 Glide 加载图像。

当 url 返回 200 状态时它有效,但有时服务器返回状态为 301 的图像。 使用 200 或 301 图像可以正确显示在浏览器中。

滑翔似乎不喜欢它。

我该怎么处理这个问题?

Glide.with(ctx)
    .asBitmap()
    .load(url)
    .apply(options)
    .error(imgError)
    .override(width,height)
    .transition(BitmapTransitionOptions.withCrossFade(GLIDE_TIME_TRANSITION))
    .addListener(object : RequestListener<Bitmap> {
        override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {
            // WHAT TO DO HERE ?
            return false
        }

        override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {               
            return false
        }

    })
    .into(this)

我想我必须在 onLoadFailed 中做一些事情,但我不确定,也不知道如何实现它......

感谢您的帮助。

I'm trying to load images with Glide.

It works when url return a 200 status but sometimes the server return the image with a status 301.
With 200 or 301 the image is correctly showing in the browser.

Glide doesn’t seem to like it.

How am I supposed to handle this ?

Glide.with(ctx)
    .asBitmap()
    .load(url)
    .apply(options)
    .error(imgError)
    .override(width,height)
    .transition(BitmapTransitionOptions.withCrossFade(GLIDE_TIME_TRANSITION))
    .addListener(object : RequestListener<Bitmap> {
        override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {
            // WHAT TO DO HERE ?
            return false
        }

        override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {               
            return false
        }

    })
    .into(this)

I think I have to do something in onLoadFailed but I'm not sure and I dont know how to achieve it...

Thank's for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文