On Jan 31, 2011, at 6:27 AM, agathe begault wrote:
> 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
>
> --
> You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-
> talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> .
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
> .
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.