I unexpectedly ran into this problem, and it took me a while to figure
out what was going on. I'm wondering if anyone has any suggestions on
how to handle it.

I'm using the 'upload' field type with SQLFORMs to upload files to the
server. However, for certain files with longer names, I get this
exception:

<type 'exceptions.IOError'>([Errno 2] No such file or directory: 'C:\
\Users\\---------------\\Documents\\------\\---------------\
\--------------------------\\web2py\\applications\\webcollection\
\databases\\..\\uploads\\usermodel_file_store.file.9dbf56ec79482a5b.
68616c6f6c7a2d646f742d636f6d2d6e36342d736e65732d796f756d696768746265747279696e67746f686172642e6a7067.jpg')

(Dashes are hiding my personal folder names, they don't actually
appear like that)

I couldn't for the life of me figure out what was going on, until I
luckily tried uploading a file with a short name, which worked
perfectly.

Doing some digging, it looks like Windows has a maximum length of 260
characters for a file's combined path and name (http://
windows.microsoft.com/en-US/windows-vista/File-names-and-file-name-
extensions-frequently-asked-questions). Doing some experimenting in
windows explorer, this appears accurate.

So, between my long base path and the long encoded file names, I'm
hitting that limit.

All that out of the way, I guess I have two questions:
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?
2) Is there any way for web2py to better identify this exception? I
could imagine some people scratching their heads for a quite a while
on it.

Reply via email to