Thanks, Niphlod - that looks like it should solve the issue. Just have a 
follow-up question - what's the best way to pass the location of the file 
to the 'open()' function? I've tried a few things, including the following:

        image_filename_as_list = current_image.image.split('.')
        cur_image_location = path_join(request.folder, 'uploads',
'temp_user_images',
            '.'.join(image_filename_as_list[:2]), image_filename_as_list[2
][:2], current_image.image)
        print "cur_image_location:",cur_image_location
        stream = open(cur_image_location, 'rb')

The print statement seems to show the correct file location. However, the 
open() command causes an exception, and the exception shows a different 
file path from what was output by the print statement; specifically, the 
'temp_user_images' portion is modified to just 'images'. Any 
recommendations? Thank you.



On Sunday, August 31, 2014 11:29:44 AM UTC-5, Niphlod wrote:
>
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to