Thanks, Niphlod. I've gotten closer to a solution with your suggestion. 
However, there's still something of an issue. I start off by storing the 
path to the image field which I would like to copy, and creating a stream 
for the corresponding image

        image_filename_as_list = image_row.image_upload_field.split('.')
        cur_image_file = path_join(request.folder, 'uploads', '.'.join(
image_filename_as_list[:2]),
            image_filename_as_list[2][:2], cur_user_image.image)
        stream = open(cur_image_file, 'rb')

If I pass the path of the image file location to insert(), as in the 
following line of code, the image file copy is not created, but the 
corresponding thumbnail is created through the use of the thumbnail field's 
compute parameter.

        image_id = db.t_image1.insert(image = cur_image_file)

If I pass the stream in the following way, the same thing occurs: the 
thumbnail is created/computed, but the image is not copied.

        image_id = db.t_image1.insert(image = stream)

On the other hand, if I do the following, a randomly-named image file 
appears (with a ".txt" extension) in the appropriate folder, and a folder 
is created for the thumbnail file, but no thumbnail file is created.

        image_id = db.t_image1.insert( f_image_file = db.t_image1.image.
store(stream, 'some name'))

Can you offer a suggestion for how to handle this so that both the image 
file (with a reasonable name) and the corresponding thumbnail are both 
created? 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to