From: Kieran K. <kie...@ma...> - 2009-07-02 10:39:57
|
Hi all, Trying to deal with default behavior issue regarding webPath attribute of ERAttachment. The docs indicate the behavior I would like, but the logic does something different.... The docs under the section "Path Templates" say: ${ext} Attempts to lookup the mime type of the original file (based on its original extension) and returns the primary file extension for that mime type including a "." prefix. For instance, if a user uploads an image/jpg attachment with the original extension .JPEG, the variable replacement would be ".jpg". If there is no mime type found, or the mime type does not have a primary extension, the original extension of the file is used. If there is no original extension, this variable will replace with a blank (i.e. no dot). The problem is that every unknown mime type gets a '.dat' file extension in webPath rather than the original file extension of the uploaded file. So common files such as Excel, Word, PowerPoint, etc. all get '.dat'.... resulting in bad user experience when clicking on those attachment links. In the code, the mimeType is primary means to get a webPath file extension, as shown here in ERAttachmentProcessor#_parsePathTemplate: ..... however in ERAttachmentProcessor#process(...) the mime type is set to 'application/x-octet-stream' here before the webPath is ever calculated: Workaround: define a webPath to use original file name: er.attachment.db.webPath=/${pk}/${fileName} (BTW, I notice that database webpaths already have id in path (...id/ pk/webPath...), so is the pk really even needed for uniqueness in this property? for example: ..app.woa/-63935/attachments/id/19/19/ExcelExample.xls Possible better default behavior solutions for our favorite framework: if mimeType is the default 'application/x-octet-stream', then prefer the uploaded file extension. If Mike likes this solution, I can do a patch if he would like that. Regards, Kieran |