Hello everybody,
I'm trying to allow users to download a file from a server (like a
Sharepoint one) with a link in my application.
Here is the view:
...
<td id="with_icon"><%= link_to image_tag("up.png", :alt =>
"Download the document", :border => 0, :id => "icon"), d.document_url
%></td>
...
As you can see, i give an url to the link_to method. I would like to
know if the link is valid or not. I mean if it return really a file or
not.
I tried some methods like this one :
def remote_file_exist?(url)
res = Net::HTTP.get_response(URI.parse(URI.encode(url))) rescue
SocketError
res
end
This kind of method return an error for some valide urls and no error
for some invalide urls.
Have you any idea or suggestion ?
Hello everybody,
I'm trying to allow users to download a file from a server (like a
Sharepoint one) with a link in my application.
Here is the view:
...
<td id="with_icon"><%= link_to image_tag("up.png", :alt =>
"Download the document", :border => 0, :id => "icon"), d.document_url
%></td>
...
As you can see, i give an url to the link_to method. I would like to
know if the link is valid or not. I mean if it return really a file or
not.
I tried some methods like this one :
def remote_file_exist?(url)
res = Net::HTTP.get_response(URI.parse(URI.encode(url))) rescue
SocketError
res
end
This kind of method return an error for some valide urls and no error
for some invalide urls.
Have you any idea or suggestion ?
I don't have any code for you, but I do have an idea. Why not set up a cron/rake task to read all the URLs in your database at some interval, send a HEAD request to each of them to see if they resolve, and then mark your database with the result of this test. Keep checking -- don't just write off a bad response, because the server could have been having a senior moment.
Walter