Dear All,
I have a problem with Field('upload). It seems that some file names produce
an error in DAL.
Let's take a "test" app to reproduce it.
1) A simple model :
db = DAL('mysql://user:pass@myServer')
db.define_table('file',
Field('title', label=T('Title'), notnull=True),
Field('file', 'upload', uploadfolder=os.path.join(
request.folder,'static','uploaded_files'
), notnull=True, autodelete=True, label=T('File')),
format='%(title)s'
)
2) a controller :
def files():
a_file = db.file(request.args(0))
crud.settings.update_deletable=False
if len(request.args) and a_file:
crud.settings.update_deletable = False
form = crud.update(db.file,a_file,next='files_list')
else:
form = crud.create(db.file)
return dict(a_file=a_file, form=form)
3) A view "files.html":
{{extend 'layout.html'}}
{{ if a_file: }}
<h1>{{=T('Edit file')}}</h1>
{{ else: }}
<h1>{{=T('Add a file')}}</h1>
{{ pass }}
{{=form}}
Then go on http://127.0.0.1:8000/test/default/files/
Try to upload a file : everything works fine
Create a simple file (regardless the type, it can be a txt file or anything
else) but named *Audi A6 Avant 3.0 V6 TDI 240 DPF Quattro Tiptronic S Line
(Break) 10_2009, Packs et options - Cote automobile - autoplus.fr.txt* or
take the attached file
Try to upload this file : you got the fllowing error
Error ticket for "test" Ticket ID
127.0.0.1.2013-03-16.11-43-07.109e09df-378c-4e89-96b1-175c300f70d6
<type 'exceptions.IOError'> [Errno 2] No such file or directory:
'D:\\Google
Drive\\loic\\web2py\\web2py\\applications\\test\\static\\uploaded_files\\file.file.accd0d98e01c0b64.41756469204136204176616e7420332e30205636205444492032343020445046205175617474726f2054697074726f6e69632053204c696e652028427265616b292031305f323030392c205061636b73206574206f7074696f6e73202d20436f7465206175746f6d6f62696c65202d20.txt'
Version web2py™ (2, 4, 2, 'stable', datetime.datetime(2013, 3, 4, 3, 26,
21)) Python Python 2.7.2: C:\Python27\python.exe (prefix: C:\Python27)
Traceback
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
Traceback (most recent call last):
File "D:\Google Drive\loic\web2py\web2py\gluon\restricted.py", line 212, in
restricted
exec ccode in environment
File "D:/Google
Drive/loic/web2py/web2py/applications/test/controllers/default.py"
<http://127.0.0.1:8000/admin/default/edit/test/controllers/default.py>, line
87, in <module>
File "D:\Google Drive\loic\web2py\web2py\gluon\globals.py", line 193, in
<lambda>
self._caller = lambda f: f()
File "D:/Google
Drive/loic/web2py/web2py/applications/test/controllers/default.py"
<http://127.0.0.1:8000/admin/default/edit/test/controllers/default.py>, line
84, in files
form = crud.create(db.file)
File "D:\Google Drive\loic\web2py\web2py\gluon\tools.py", line 3631, in create
**attributes
File "D:\Google Drive\loic\web2py\web2py\gluon\tools.py", line 3572, in update
detect_record_change=self.settings.detect_record_change):
File "D:\Google Drive\loic\web2py\web2py\gluon\sqlhtml.py", line 1459, in
accepts
field.uploadfolder)
File "D:\Google Drive\loic\web2py\web2py\gluon\dal.py", line 9228, in store
dest_file = open(pathfilename, 'wb')
IOError: [Errno 2] No such file or directory: 'D:\\Google
Drive\\loic\\web2py\\web2py\\applications\\test\\static\\uploaded_files\\file.file.accd0d98e01c0b64.41756469204136204176616e7420332e30205636205444492032343020445046205175617474726f2054697074726f6e69632053204c696e652028427265616b292031305f323030392c205061636b73206574206f7074696f6e73202d20436f7465206175746f6d6f62696c65202d20.txt'
I think the file name contains not allowed characters but I don't
understand what is the exact problem...
Can anyone explain me?
I'm on Windows7 pro x64, Python 2.7.2, Web2py 2.4.2, MySQL 5.5.29
Thank you
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
test