Question

Check if it is possible to download file with delphi

Good day ... I'm starting in Delphi and I am creating a program to download files from HTTP ...

I'm using:  

IdHTTP.Get (URL FileDownload)

But my program generates error when it can not download the file ...

Ex: http://exemplo.com/ -> Generates Error

Ex: http://exemplo.com/meudownload.ts -> Makes download

I'd like to correct this error, how can I check if it is possible to download the file or if it is being lowered ...

I used EIdHTTPProtocolExeption but only checks HTML error like: 404, 300 ... and is not that I wish ...

I would like to see if you can download the file, or if it is being downloaded ...

If this happens I will download other file:

donw_1.ts, down_2.TS, down_3.TS ... then when he gets el Archiving one that can not be downloaded, I have the answer to cancel the loop ...

Was it helpful?

Solution 3

Unable to solve the problem by doing a scan HEAD ... and managed to solve the problem with the HTTP 404 error .... where there was no file to download it generates this error EIdHTTPProtocolExeption ... the problem has been resolved ....

OTHER TIPS

Catching the EIdHTTPProtocolException is what you should be doing. Remember that Indy is specifically designed to make use of exceptions for error reporting. EIdHTTPProtocolException is how TIdHTTP reports HTTP-specific errors from the server (any other type of exception means either the socket or the RTL had a problem and the HTTP request can be retried). The mere fact that you get that exception means the server could not deliver the file as requested, so you typically should not retry unless you know it is a recoverable error. Checking the exception ErrorCode is optional, but available if you really need to differentiate between specific errors.

If you just want to see if a file exists on the server, use TIdHTTP.Head. This function just downloads the headers that would have been returned from the equivalent Get call, but not the data itself. You can then check the headers to see if the file exists and decide what to do next.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top