获取内容类型的最快方法 [英] Quickest way to get content type
问题描述
我需要搜索用户插入的网址的内容类型(如果是图像,音频或视频)。我有这样的代码:
I need to chech for the content type (if it's image, audio or video) of an url which has been inserted by the user. I have a code like this:
URL url = new URL(urlname);
URLConnection connection = url.openConnection();
connection.connect();
String contentType = connection.getContentType();
我正在获取内容类型,但问题是它似乎有必要下载整个文件来检查它的内容类型。因此,当文件非常大时,它会持续太长时间。我需要在Google App Engine应用程序中使用它,因此请求限制为30秒。
I'm getting the content type, but the problem is that it seems that it is necessary to download the whole file to check it's content type. So it last too much time when the file is quite big. I need to use it in a Google App Engine aplication so the requests are limited to 30 seconds.
有没有其他方法可以获取网址的内容类型而无需下载文件(这样可以更快完成)?
Is there any other way to get the content type of a url without downloading the file (so it could be done quicker)?
推荐答案
如果其他端支持它,你能否使用 HEAD
HTTP方法?
If the "other" end supports it, could you use the HEAD
HTTP method?
这篇关于获取内容类型的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!