File objects with illegal characters
What is the best way to deal with file uploads with illegal characters? I have no problem stripping the filenames such that "_Peter[1].doc" becomes "Peter1.doc" before it's manage_addFile'ed. But suppose I want to maintain the exact filename as it was on the harddrive, how do you deal with that? -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
On 29 Aug 2005, at 16:13, Peter Bengtsson wrote:
What is the best way to deal with file uploads with illegal characters? I have no problem stripping the filenames such that "_Peter[1].doc" becomes "Peter1.doc" before it's manage_addFile'ed. But suppose I want to maintain the exact filename as it was on the harddrive, how do you deal with that?
What is the use case? If a filename is illegal as a URL then that's that. All you could possibly do would be to stick the illegal name into another attribute and show it as additional piece of information for the content. You cannot make an illegal filename legal as a URL for download, unless you hack the regexes in CMF/Zope and just disregard interoperability. jens
What is the best way to deal with file uploads with illegal characters? I have no problem stripping the filenames such that "_Peter[1].doc" becomes "Peter1.doc" before it's manage_addFile'ed. But suppose I want to maintain the exact filename as it was on the harddrive, how do you deal with that?
What is the use case?
Nothing in particular. I've been working on inbound email file attachments with weird (window$ guily) file names. http://www.issuetrackerproduct.com/News/inbound-email-feature-set-up-for-tes...
If a filename is illegal as a URL then that's that. All you could possibly do would be to stick the illegal name into another attribute and show it as additional piece of information for the content. You cannot make an illegal filename legal as a URL for download, unless you hack the regexes in CMF/Zope and just disregard interoperability.
Good point. I'm confident there's no need to do for the web then. However, there might be a solution for those who'd want to do it by using the content-disposition header from an attribute. (but that wouldn't work with wget) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Jens Vagelpohl wrote at 2005-8-29 16:17 +0100:
... If a filename is illegal as a URL then that's that.
In fact, an URL does not disallow any characters. It only requires that some of them need to be escaped. Thus, a Zope id could contain any character, would Zope properly escape all characters not literally allowed in URLs. I have changed our Zope version to allow any character in ids different from ";" and "/". Allowing these, too, would require a different task assignment between "cgi.py" and ZPublisher (more precisely: "ZPublisher.BaseRequest.BaseRequest.traverse". -- Dieter
On 29 Aug 2005, at 18:39, Dieter Maurer wrote:
Jens Vagelpohl wrote at 2005-8-29 16:17 +0100:
... If a filename is illegal as a URL then that's that.
In fact, an URL does not disallow any characters. It only requires that some of them need to be escaped.
Thus, a Zope id could contain any character, would Zope properly escape all characters not literally allowed in URLs.
Yes, that's always a viable solution. But as you said, it might require patching deep in the bowels of Zope to get that right. Or at the application level which could escape everything before it even hits the Zope level. jens
participants (3)
-
Dieter Maurer -
Jens Vagelpohl -
Peter Bengtsson