Re: uploading files to a database
"Jonathan Ellis" <[email protected]> Wed, 18 Oct 2006 11:39:04 -0700
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
Well, the code looks correct. It works fine for me on sqlite with a blob datatype. I don't use mysql so I can't help with longblob... although I do know there have been past problems with mysql's less-standard types in SqlAlchemy. I would suggest 1) replace the sqlalchemy directory with lib/sqlalchemy from the latest sqlalachemy release 2) if that fails, you can always use a text column and base64-encode what you put into it 2a) or, just store the file data on the filesystem, and store a pointer to that in the database instead of the data itself -Jonathan On Wed, 18 Oct 2006 09:14:19 +0100, "Mary Jane Boholst" <[email protected]> said: > the data column in the db is a longblob.... > > Jonathan Ellis wrote: > > what data type is your "data" column in the database? > > > > On Tue, 17 Oct 2006 11:25:07 +0100, "Mary Jane Boholst" > > <[email protected]> said: > > > >> Hi there, > >> Sorry to bother you all again. I have managed to store something in the > >> database however I am not sure if this is the binary or not as the files > >> do > >> not display correctly. Do I need to save the file as a binary version > >> before > >> entering to the db? I attach my code if it help explain what I have done. > >> Thanks in advance for your help. > >> Regards, > >> MJ > >> > >> On Thursday 12 October 2006 17:46, Jonathan Ellis wrote: > >> > >>> you don't give your code but it looks like you are doing > >>> title=request.getpost(something), which returns a list, instead of > >>> request.getpost1 > >>> > >>> On Thu, 12 Oct 2006 15:22:17 +0100, "Mary Jane Boholst" > >>> > >>> <[email protected]> said: > >>> > >>>> How do I store the file into a db? I have tried to do this but get the > >>>> following errors: > >>>> > >>>> SQLError: (ProgrammingError) not enough arguments for format string > >>>> 'INSERT > >>>> INTO uploads (title, data, type) VALUES (%s, %s, %s)' [['test'], > >>>> '/data/', > >>>> ['text/plain']] > >>>> > >>>> Stack: /usr/share/spyce-2.1/sqlalchemy/engine/base.py:348, in > >>>> _executemany: > >>>> > >>>> > >>>> raise exceptions.SQLError(statement, parameters, e) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:319, in _execute_raw: > >>>> > >>>> > >>>> self._executemany(cursor, statement, parameters, context=context) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:282, in proxy: > >>>> > >>>> > >>>> self._execute_raw(statement, parameters, cursor=cursor, context=context) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:286, in execute_compiled: > >>>> > >>>> > >>>> proxy(str(compiled), parameters) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:270, in > >>>> execute_clauseelement: > >>>> > >>>> > >>>> return self.execute_compiled(elem.compile(engine=self.__engine, > >>>> parameters=param), *multiparams, **params) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/engine/base.py:246, in execute: > >>>> > >>>> > >>>> return Connection.executors[type(object).__mro__[-2]](self, object, > >>>> *multiparams, **params) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/mapper.py:847, in save_obj: > >>>> > >>>> > >>>> c = connection.execute(statement, params) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/unitofwork.py:599, in _save_objects: > >>>> > >>>> > >>>> task.mapper.save_obj(task.tosave_objects, trans) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/unitofwork.py:645, in execute: > >>>> > >>>> > >>>> self._save_objects(trans) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/unitofwork.py:377, in execute: > >>>> > >>>> > >>>> head.execute(self) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/unitofwork.py:207, in flush: > >>>> > >>>> > >>>> flush_context.execute(echo=echo) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/orm/session.py:234, in flush: > >>>> > >>>> > >>>> self.uow.flush(self, objects, echo=self.echo_uow) > >>>> > >>>> /usr/share/spyce-2.1/sqlalchemy/ext/sqlsoup.py:314, in flush: > >>>> > >>>> > >>>> objectstore.get_session().flush() > >>>> > >>>> uploadtest.spy:11, in (main): > >>>> > >>>> > >>>> db.flush() > >>>> > >>>> I am not sure where the problem/s is/are. I feel as if I am going around > >>>> in > >>>> circles with this. If it will help I attach the file. > >>>> Thanks in advance, > >>>> MJ > >>>> > >>>> On Wednesday 11 October 2006 17:01, you wrote: > >>>> > >>>>> You can get the data from request.file and then do whatever you like > >>>>> with it > >>>>> > >>>>> http://spyce.sourceforge.net/docs/fileupload.src.html > >>>>> > >>>>> On Wed, 11 Oct 2006 15:47:22 +0100, "Mary Jane Boholst" > >>>>> > >>>>> <[email protected]> said: > >>>>> > >>>>>> Hello again, > >>>>>> Is it possible to upload files to a database using spyce or even just > >>>>>> python? I am aware that files can be uploaded to the browser to > >>>>>> display but can these files be stored in a database? Is it possible > >>>>>> to just upload files to the server and store information about the > >>>>>> file in the database? > >>>>>> Sorry to keep bothering you all. > >>>>>> Thanks in advance, > >>>>>> MJ > >>>>>> > >>>>>> --------------------------------------------------------------------- > >>>>>> ---- Using Tomcat but need to do more? Need to support web services, > >>>>>> security? Get stuff done quickly with pre-integrated technology to > >>>>>> make your job easier > >>>>>> Download IBM WebSphere Application Server v.1.0.1 based on Apache > >>>>>> Geronimo > >>>>>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121 > >>>>>> 642 _______________________________________________ > >>>>>> Spyce-users mailing list > >>>>>> [email protected] > >>>>>> https://lists.sourceforge.net/lists/listinfo/spyce-users > >>>>>> -- C++ is history repeated as tragedy. Java is history repeated as farce. --Scott McKay ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642