code: public static String getFilename(Resource resource, String extFallback) {
          String filename = getResourceName(resource);
          if (!HAS_FILE_EXT_PATTERN.matcher(filename).matches()) {
              String filenameEnd = null;
              MimeType mimeType = getMimeType(resource);
              if (mimeType != null) {
                  String ext = mimeType.getExtension();
                  if (StringUtils.isNotBlank(ext)) {
                      filenameEnd = ext;
                  } else {
                      Matcher matcher = FILE_EXT_FROM_MIME.matcher(mimeType.toString());
                      if (matcher.matches()) {
                          filenameEnd = "." + matcher.group(1);
                      }
                  }
              }
              if (StringUtils.isBlank(filenameEnd) && StringUtils.isNotBlank(extFallback)) {
                  filenameEnd = "." + extFallback;
              }
              if (StringUtils.isNotBlank(filenameEnd) &&
                      !filename.toLowerCase().endsWith(filenameEnd.toLowerCase())) {
                  filename += filenameEnd;
              }
          }
          return filename;
      }
docs: Determines the filename for a resource using their name and the mime type of the resource
  (useful as filename hint in the HTTP headers - Content-Disposition - of a download operation).
  
  @param resource    the (binary) resource
  @param extFallback a default filename extension if no extension hint can be determined
  from the mime type
  @return the filename with an appropriate file extension