When you upload a file via an upload field, by default it goes into the
/web2py/applications/yourapp/uploads folder, though you can specify a
different folder via the 'uploadfolder' argument to Field(). The file
itself is renamed (for security reasons) to
[tablename].[fieldname].[16-char-uuid].[b16encoded-original-filename].[original-extension].
This new name is what gets stored in the upload field (the 'attachment'
field in your case). If you want to access the file, you can retrieve the
name from the 'attachment' field, and use that along with the path to the
'uploads' folder (or whatever folder you set for uploads).
Note, if you do any processing of the file, there's no need to "re-insert"
anything in the database, as the database merely stores the filename.
Anthony
On Monday, November 7, 2011 6:07:10 PM UTC-5, D.P. wrote:
>
> Anyone know how to pull an uploaded file from the database locally on the
> server? I want to do some server-side processing on the file and then
> re-insert it to the database. I'm not sure I understand how to get the
> local path on the server of the uploaded file. The static/upload directory
> appends an random ID to the files. How can I get the path to an uploaded
> file so that I can manipulate it?
>
>
> I'm using a standard model form like the following:
>
> db=DAL('sqlite://storage.db')
> db.define_table('test',
> Field('package_name'),
> Field('attachment','upload',default=''))
>
> My controller:
>
> form=SQLFORM(db.testplug)
> if form.accepts(request.vars):
> response.flash='Files uploaded'
> filename = request.vars.attachment.filename
> filereference = request.vars.attachment.file
> print filename
> print filereference
> records=SQLTABLE(db().select(db.test.ALL),upload=download)
> return dict(form=form,records=records)
>
>
>
>
>
> My view:
>
> {{=records}}
>
> [{{=A('delete all',_href=URL('delete_storage'))}}]
>
>
>
>