On Thursday, November 24, 2011 12:06:24 AM UTC-5, Massimo Di Pierro wrote:
>
> > 1) Is there an easy way to "overload" the default behavior of the
> > SQLFORM so it stores the filename in the database, instead of encoding
> > it in the renamed-file? I see the Field class has a custom_store/
> > retrieve variable, could I just duplicate the default DAL store/
> > retrieve functions and add my extra file name logic? Or is there a
> > better way?
>
> One thing you can do it is
>
> Field('name','upload',length=260)
>
> it will truncate the generated filename to 260.
>
Note, I think using the 'length' arg in this way requires trunk. In the 
current stable version, it automatically limits the filename to 200 
characters (plus extension). If you set length to less than 200, I'm not 
sure what happens.

In trunk, length defaults to 512, but if you set it lower, it will limit 
the entire filename (including extension) to that length. Note, the 
filename is of the form

[table].[field].[16-char uuid fragment].[b16encoded original 
filename].[extension]

If that ends up longer than 'length', it gets truncated from the end 
(though the extension is not truncated). So, depending on the table and 
field names, you need about 40 characters even without encoding the 
original filename at all.

Also, note that the 'length' argument applies to the filename only -- it 
does not include the full path length, so you have to account for that 
separately when setting the length (maybe we should have it apply to the 
full path length when the file is being stored on the filesystem).

Anthony

Reply via email to