The new name is stored in the 'attachment' field of the record inserted. After the form.accepts, you can also access it via form.vars.attachment (and for backward compatibility, form.vars.attachment_newfilename).
Anthony On Tuesday, November 8, 2011 10:33:07 AM UTC-5, D.P. wrote: > > Thanks for the information Andy. > > The documentation states that you can retrieve renamed file from the > 'attachment' field, but I'm not sure exactly how. I can get the pointer > (<open file '<fdopen>', mode 'w+b' at 0x02549440>) by using > request.args.attachment.file and also the temp filename by adding > .name--but that shows a local temp destination as opposed to the renamed > file in the 'uploads' folder. How can I get the new name? > > Any help is appreciated. > > On Mon, Nov 7, 2011 at 6:51 PM, Anthony <abas...@gmail.com> wrote: > >> 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'))}}] >>> >>> >>> >>> > > > -- > D.P. >