uploads_in_blob in MongoDBAdapter doesn't let upload file to folder

12 views
Skip to first unread message

Francisco Costa

unread,
Nov 11, 2013, 11:23:36 AM11/11/13
to web2py-d...@googlegroups.com
Why is MongoDBAdapter with uploads_in_blob = True?

By default I can't upload a file using

import os
db
.define_table(
   
'data_file',
   
Field('title'),
   
Field('file', 'upload', uploadfield=True, uploadfolder=os.path.join(request.folder, 'uploads/'))
)


I get this error:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Traceback (most recent call last):
File "/home/franciscocosta/www/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
File "/home/franciscocosta/www/web2py/applications/test/controllers/default.py", line 51, in <module>
File "/home/franciscocosta/www/web2py/gluon/globals.py", line 372, in <lambda>
self._caller = lambda f: f()
File "/home/franciscocosta/www/web2py/applications/test/controllers/default.py", line 27, in upload_data
request.vars.multi_file.file, request.vars.multi_file.filename))
File "/home/franciscocosta/www/web2py/gluon/dal.py", line 8781, in insert
ret = self._db._adapter.insert(self, self._listify(fields))
File "/home/franciscocosta/www/web2py/gluon/dal.py", line 5614, in insert
values = self._insert(table, fields)
File "/home/franciscocosta/www/web2py/gluon/dal.py", line 5604, in _insert
values[fieldname] = self.represent(v, fieldtype)
File "/home/franciscocosta/www/web2py/gluon/dal.py", line 5408, in represent
return Binary(value)
File "/usr/local/lib/python2.7/dist-packages/bson/binary.py", line 133, in __new__
"instance of %s" % (binary_type.__name__,))
TypeError: data must be an instance of str


If I turn uploads_in_blob = False in DAL (line 5255) the file is created on the uploads directory.

Could we make uploads_in_blob an adapter_args?

Something like this:

    db = DAL('mongodb://localhost/%s' % request.application,
            pool_size
=10,
            adapter_args
={'safe': False, 'uploads_in_blob': False},
       
)



Reply all
Reply to author
Forward
0 new messages