Re: uploading files to a database

Mary Jane Boholst <[email protected]> Fri, 13 Oct 2006 10:18:59 +0100
Newsgroups gmane.comp.python.spyce.general
Organization IOP
Message-ID <[email protected]>
Opps sorry. I attach a slightly modified version of my code which is still 
giving the error.
Cheers,
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

-------------------------------------------------------------------------
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

_______________________________________________
Spyce-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spyce-users
uploadtest.spy (text/html, 1.1 KB)
<spy:parent title="Upload Summer School Files" />
[[\ 
if request.post('ct'):
  response.setContentType(request.post1('ct'))
  if request.file('upfile')!=None:
    data=request.file('upfile').file
    title=request.post1('description')
    ct=request.post1('ct')
    file = data.read
    db.uploads.insert(title=title,data=file,type=ct)
    db.flush()
    files = db.uploads.select_by(db.uploads.title=='title')
    for file in files:
    	print files.id
  else:
    print 'file not properly uploaded'
  raise spyceDone
]]
<html><body>
 Choose a file to upload..<br>
  [[-- input forms --]]
  <hr>
  <table>
    <form action="[[=request.uri('path')]]" method=post 
        enctype="multipart/form-data">
      <tr>
        <td>File description:</td>
        <td><input type=text name=description></td>
      </tr>
	<tr>
        <td>file:</td>
        <td><input type=file name=upfile></td>
      </tr>
	<tr>
        <td>content-type:</td>
        <td><input type=text name=ct></td>
      </tr>
	<tr>
        <td><input type=submit handler=action.upload value=ok></td>
      </tr>
    </form>
  </table>
</body></html>