public static String toContentType(File file) {
        String fName = file.getName();
        String[] parts = fName.split("\\.");
        String ext = parts[parts.length - 1].toLowerCase();

        if (ext.equals("png") || ext.equals("jpg") || ext.equals("jpeg") || ext.equals("gif"))
            return "image/" + ext;
        else if (ext.equals("mp4") || ext.equals("ogv"))
            return "video/" + ext;
        else if (ext.equals("mp3") || ext.equals("ogg"))
            return "audio/" + ext;
        else
            return null;
    }