when you deal with upload fields, you should use the proper method (i.e. 
store())

http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#More-on-uploads

On Sunday, August 31, 2014 2:52:45 PM UTC+2, Spokes wrote:
>
> I have two tables, *t_image2* and *t_image1*, and I would like to copy an 
> image (type: 'upload') from* t_image2* to *t_image1*.The tables are 
> something like the following: 
>
> db.define_table('t_image2',
>     ...
>     Field('name', requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db, '
> t_image2.name')], unique=True, notnull=True),
>     Field('image', 'upload', uploadseparate=True, autodelete=True,     
>           uploadfolder=os_path_join(request.folder,'uploads/temp_images'),
>           requires=[IS_NOT_EMPTY(), IS_IMAGE()]),
>           ...
>           )
>
> db.define_table('t_image1',
>     ...
>     Field('name', requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db, '
> t_image1.name')], unique=True, notnull=True),
>     Field('image', 'upload', uploadseparate=True, autodelete=True, 
> uploadfolder=os_path_join(request.folder,'uploads/images'),
>             requires=[IS_NOT_EMPTY(), IS_IMAGE()]),
>     Field('thumbnail','upload',  
>            uploadseparate=True, readable=True, writable=False, autodelete=
> True,      
>            uploadfolder=os_path_join(request.folder,'uploads/thumbnails'),
>            compute=lambda row: SMARTHUMB('t_image1', row.image, (200, 150
> ), 
>            upload_folder = 'uploads/thumbnails', request = request)),
>            ...)
>
> It's possible to do this:
>
> db.t_image1.insert(name = [some name], image = [image_from_t_image2.image
> ])
>
> But this merely copies the entries that are in one table to the other, 
> without making a copy of the file in question. It also doesn't trigger the 
> *t_image1* 'thumbnail' field's 'compute' function, which would create the 
> thumbnail file. 
>
> Is there a better way to perform this sort of file copy from one table to 
> another, such that the copy of the file is automatically made (and if 
> necessary, the new folder is created), and which triggers the creation of 
> the thumbnail? Or is it necessary to perform the folder creation and file 
> copy operation, as well as the creation of the thumbnail, manually? Thank 
> you.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to