cancel
Showing results for 
Search instead for 
Did you mean: 

Task attachment file extension and mime type

zfranken
Champ in-the-making
Champ in-the-making
I'm wondering why the file extension is removed from the filename when an attachment is stored on a task.  This is causing a headache with Office 2007 files.  For example, if I upload "File.xlsx" as an attachment, when I go to download it, it is now called "File.vnd.openxmlformats-officedocument.spreadsheetml.sheet".  I thought adding the mime mappings to the main web.xml in tomcat might help, but not so.  Any thoughts?
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
Is this in the new (5.7) explorer? If so, than it certainly sounds like a bug (but I tested it with several office docs … but it can always happen ofc).

zfranken
Champ in-the-making
Champ in-the-making
I'm very new to Activiti, so I've only tried 5.7.  I don't think it's so much a problem with Office documents as it is the way attachments are stored.  Attachments are saved without a file extension and then when they are downloaded the extension is derived from the mime type and appended to the file name.  This will be a problem until Microsoft gets its act together and starts using the mime type rather than file extensions.  In my opinion the file name should be stored as is with the extension intact.  However, perhaps I'm missing the motivation for removing the file extension.

Looks like the relevant code is in (at least) FileAttachmentEditorComponent and GenericAttachmentRenderer:

   
protected String getFriendlyName(String name)
    {
        if(name != null)
        {
            String friendlyName = null;
            int lastDotIndex = name.lastIndexOf(".");
            if(lastDotIndex > 0)
                friendlyName = name.substring(0, name.length() - (name.length() - lastDotIndex));
            else
                friendlyName = name;
            return friendlyName.replace("_", " ").replace("-", " ");
        } else
        {
            return name;
        }
    }


protected String extractExtention(String type)
    {
        int lastIndex = type.lastIndexOf('/');
        if(lastIndex > 0 && lastIndex < type.length() - 1)
            return (new StringBuilder()).append(".").append(type.substring(lastIndex + 1)).toString();
        else
            return (new StringBuilder()).append(".").append(type).toString();
    }

frederikherema1
Star Contributor
Star Contributor
Indeed, that doesn't seem right, I'll take care of it…