File upload and import issues - The file(s) uploading failed

Problem

I am trying to upload a file to the server and I get a message "The file(s) uploading failed".

The reason for this is to improve security in the application, a whitelist of allowed file types and their content type, is included in the server.  Whenever a file is uploaded, we check the file extension against the list of allowed files and then check the file content against pre-defined standards, to ensure the file is in the format indicated by the extension.

What you are attempting is the import of a file that is not in the exact format expected, so to prevent the application, upload is blocked.  You can check the Content Type in the server logs, then a decision can be made as to whether you want to allow this type of content in the server.

The file whitelist is found in the "Administrator->File Extensions" menu.  In the out of the box configuration, we include extensions and content type necessary for operation of the base configuration.  If additional content types are required, you can enable them.  For example, we support import of device message strings in an Excel format.  It is possible that strings could be edited and saved in OpenOffice, but while this creates an "Excel compatible" file, importing against the base configuration will fail as although it is "compatible", it is not an Excel file.  In this case, Administrators could choose to add the OpenOffice format to the list of allowed content type.

As this extra level of security has been added, files that you previously imported may be rejected by the server (as content checking now takes place).  If this occurs, you can investigate which content is stored in the file by reviewing the server logs and add to the allowed file extension list.

Before adding new filetypes

Before adding new content types, you are responsible for ensuring that the content type is valid for use in the application and that the code could not be malicious.  If, for example, you add new content type just because the system rejected your file, this removes the protection that the whitelist provides.  You should validate the content in an external application before adding to the Swift MEAP server.

Investigation

If when uploading a file, you encounter the message "The file(s) uploading failed", please perform the following steps to identify why the upload failed:.  You will need to check what the content is within the file you are uploading and whether that should be added to the "File Extensions" menu. 

To check content type:

NOTE: Logs should be at debug level for troubleshooting.  If necessary, you can set logging to "Debug", attempt the file upload and then switch the logs back to previous settings.  We need to capture the upload attempt to identify the file content type. 

In this example, we will attempt to import an .xlsx device message string saved by OpenOffice (this is not a filetype added by default to the server).

  1. With the logs in debug mode, attempt to upload the file you are having an issue with (keep a note of the exact filename)
  2. Navigate to Utility->Show Logs and download the latest log file (or console log in a split port server)
  3. Open the log file in a text editor and search for the filename that you attempted to import
  4. Locate the entry for "isContentTypesMatching" in the log file downloaded, this indicates where the file content is checked.  In the following example we have attempted to upload "ENU_DeviceMessages.xlsx", the entry in the logfile is:
    1. [2014-12-05 03:02:35,650]FATAL573969(StaticUtilities.java:1674) - isContentTypesMatching failed for 03-02-35 AM  ENU_DeviceMessages.xlsx, with Contenttype application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. Configured Contenttype is application/vnd.ms-excel
  5. In the above log entry, we can see the following items:
    1. ENU_DeviceMessages.xlsx - this is the file we attemted to upload, the extension "xlsx" will be used to check the content type against our "File extensions" list
    2. with Contenttype application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - this is the content type found within the file that was uploaded 
    3. Configured Contenttype is application/vnd.ms-excel - this is the content type configured in the admin console, as the file showed content of a different type, uploading was blocked

Therefore, in the admin console, we would need to add content type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" to the list of acceptible content for xlsx files.  If this is done, the importing will succeed.

Solution

To add a new file extension / content type to the console:

  1. Open Administrator->File Extensions
  2. Check existing file extensions, does the file extension you are trying to configure exist in the list?
    1. No existing file extension exists for the file type I am adding:
      1. Click on "Create New" button
      2. Add the file extension in the box labelled "Extension".  Do not add the full stop in the extension box, entries should just contain the extension, for example: xlsx
      3. Add the valid content type in the box labelled "Content Type", for example: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    2. An entry already matches the extension I want to configure:
      1. Tap the "Edit" icon next to the entry that you wish to modify
      2. You can add more than one "content type" to an existing extension by inserting the "|" (pipe / vertical bar) symbol between entries.  Add "I" follwed by your content type:
        1. For example, if an entry existed for "application/vnd.ms-excel" and you wish to add "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", the entry should read: "application/vnd.ms-excel|application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        2. Select "Update"
  3. You can now attempt to re-import the file that previously failed.  If you still cannot import, you will need to recheck the log file to check the message returned.