Reputation: 6969
How can I detect if a given URL is a file to be downloaded?
I came across the content-disposition
header, however it seems that this isn't a part of http 1.1 directly.
Is there a more standard way to detect if the response
for a GET
request made to a given URL
is actually a file to/can be downloaded?
That is the response is not html or json or anything similar, but something like an image, mp3, pdf file etc.?
Upvotes: 0
Views: 1240
Reputation: 1297
Could checking for a file extension be a possibility? Sorry I can't enlarge on that much without knowing more, but I guess you could consider using PHP to implement this if HTML doesn't have enough functionality?
Upvotes: 0
Reputation: 6969
I ended up using the content-type
to decide if it's an html file or some other type of file that is on the other end of a given URL.
I'm using the content-disposition
header content to detect the original file name if it exists since the header isn't available everywhere.
Upvotes: 0
Reputation: 191
HTTP is a transfer protocol - which is a very different thing to hard drive storage layouts. The concept of "file" simply does not exist in HTTP. No more than your computer hard drive contains actual paper-and-cardboard "files" that one would see in an office filing system.
Whatever you may think the HTTP message or URL are saying the response content does not have to come from any computer file, and does not have to be stored in one by the recipient.
The response to any GET message in HTTP can always be "downloaded" by sending another GET request with that same URL (and maybe other headers in the case of HTTP/1.1 variants). That is built into the definition of what a GET message is and has nothing to do with files.
Upvotes: 2