如何使用 GWT 检查给定的图像 URL 是否存在? [英] How can I check if the given URL of an image exists using GWT?

查看:20
本文介绍了如何使用 GWT 检查给定的图像 URL 是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查给定的 URL 是否存在并且它是一个图像,以便从中创建一个 new Image(String url).如果给定的 URL 不是图像,则应返回错误.

I want to check if a given URL exists and it's an image, in order to create a new Image(String url) from it. If the given URL is not an image then it should return an error.

推荐答案

您可以使用 RequestBuilder 来做到这一点——只需请求图像 URL,使用 Response's getHeaders() 方法获取内容类型,并检查它是否是图像.

You could do this with a RequestBuilder -- just request the image URL, use the Response's getHeaders() method to get the content type, and check if it's an image.

这篇关于如何使用 GWT 检查给定的图像 URL 是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆