views:

141

answers:

3

We need the user to be able to enter URLs in our media section . However since users can make mistakes in entering the URLs , we need to ensure that the URLs are valid flickr URLs . Valid URL eg : http://www.flickr.com/photos/53067560@N00/sets/72157606175084388/

Invalid URL eg : http://www.flickr.com/photos/53067560@N00/sets/12345/

Flickr offers API services , but I could not find one that would validate a URL .

+1  A: 

You could make an http HEAD request to the URL and check the http response code. Any response code greater than or equal to 200 and less than 300 is ok. In all likelyhood good URLs will return 200 code.

Asaph
A: 

I am pretty sure you can at least use `flickr.photos.getInfo' to see if the photo in question exists. The rest of the URL can be validated according to the result received.

You can't check for every possible permutation of course but when it comes to photo id, I am pretty certain you can rely on Flickr API... or else, they would be in trouble themselves, no?

Of course, you can double-check by issuing an HTTP GET request on the URL and verify that the result HTTP code is something like 200 (or maybe something >=200 & <=300).

jldupont
+3  A: 

The easiest way would be to make a HTTP HEAD request to the url, which would mean the URL is valid if it returns a HTTP response code of 200.

You could also use regex to ensure that it matches the expected pattern, which would possibly cut down the amount of requests you would have to make.

Yacoby