Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

retrieve if a file exists in an http server

Hello,
we have a large list of file stored in a http server with a database storing the path and file name.
Is there a way to iterate for each file in the database and retrieve the http error code (ex. 404)?
Thanks,
Labels (2)
5 Replies
Anonymous
Not applicable
Author

Hi 
Read the file path or file name from database, and then iterate each one and fetch it from HTTP serve with tFileFetch, uncheck 'die on error' option if you want the job continue to retrieve next file even there is an error. eg:
tMysqlInput--main--tFlowToIterate--iterate--tFileFetch
Anonymous
Not applicable
Author

Thanks,
but I do not want to retrieve the file but to ensure the file is present, as we have many files which are not existing or has been moved to anohter location.
So it is to get the status when the file does not exist anymore at the stored location
cheers.
Anonymous
Not applicable
Author

Hi 
Write a routine function to do it, here is an example code in this page:
http://stackoverflow.com/questions/4596447/check-if-file-exists-on-remote-server-using-its-url
Call the routine function on tMap or tJavaRow, eg:
tMysqlInput--main--tJavaRow--main--tLogRow
Anonymous
Not applicable
Author

Ok this is the first time I will use a routine.
I have create a new routine call HttpFileCheck.
And I paste the code from the link you have provided, is it correct like below?
Thanks,
package routines;
public class HttpFileCheck {
    import java.net.*;
    import java.io.*;
    public static boolean exists(String URLName){
        try {
          HttpURLConnection.setFollowRedirects(false);
          // note : you may also need
          //        HttpURLConnection.setInstanceFollowRedirects(false)
          HttpURLConnection con =
             (HttpURLConnection) new URL(URLName).openConnection();
          con.setRequestMethod("HEAD");
          return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
        }
        catch (Exception e) {
           e.printStackTrace();
           return false;
        }
      }
}
Anonymous
Not applicable
Author

Hi
I did't test the code, but I think it is OK for you to check the file if it exists. Please test it and let me know if it is OK or any problem you get.