how to get an file from another application dynamically and check the file format and read the file after that store in the mendix database?

I wanted to import the file from another application and check the format and read it in current application and wanted to store in current application database.
2 answers


You can try REST Service using form data to get the file into other application and pass both file and filename into other application and based on the name you can identify the file type.


You could upload the file in a entity then check the file extension via the filename that is used and then process the file further. A simple check like

substring(fileentity/Name,findLast(fileentity/Name, ‘.’ )

Will return the extension (might need a +1 to skip the period character) and then you could base your further logic on that.

Or more complex write a java action that reads the content of the file like in the simple example below in pure java (needs some rewrite in Mendix actions):


public class FileFormatVerifier {
  public static void main(String[] args) throws IOException {
    if (args.length != 1) {
      System.out.println("Usage: FileFormatVerifier <file>");

    String fileName = args[0];
    String fileFormat = getFileFormat(fileName);
    if (fileFormat == null) {
      System.out.println("Unable to determine file format for " + fileName);
    } else {
      System.out.println("File format for " + fileName + " is " + fileFormat);

  public static String getFileFormat(String fileName) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(fileName));
    String firstLine = reader.readLine();

    if (firstLine.startsWith("<?xml")) {
      return "xml";
    } else if (firstLine.startsWith("P3")) {
      return "ppm";
    } else if (firstLine.startsWith("GIF87a") || firstLine.startsWith("GIF89a")) {
      return "gif";
    } else {
      return null;

Hope this gives you some ideas on how to proceed.