Actually, on GAE, I don't think you have to explicitly define the blob
field at all -- the DAL will automatically create a blob field for each
upload field and store uploaded files in the blob field. So, I think this
should work:
dal_db.define_table('UserImageStore',
Field('profile_image', 'upload'),
Field('upload_ts', 'datetime'),
Field('change_ts', 'datetime'))
dal_db.UserImageStore.insert(
profile_image=dal_db.UserImageStore.profile_image.store(profile_image,
<name
you want to give>),
upload_ts=datetime.now(),
change_ts=datetime.now())
Anthony
On Monday, June 18, 2012 11:09:54 AM UTC-4, Sushant Taneja wrote:
>
> Sorry got confused.
> Made it work !
>
> Here is the final code :
>
> dal_db.UserImageStore.insert(profile_image =
> dal_db.UserImageStore.profile_image.store(profile_image,<name you want to
> give>),
> profile_blob = profile_image,
> upload_ts = datetime.now(),
> change_ts = datetime.now()
> )
>
> Thanks Anthony !
>
> On Monday, June 18, 2012 8:28:25 PM UTC+5:30, Sushant Taneja wrote:
>>
>> Will this work on AppEngine ? Since there is no filesystem
>>
>> The code for manual uploads is :
>>
>> stream = open(filename,'rb')
>>
>> Will this not give error since it will not be able to find the file ?
>>
>> On Monday, June 18, 2012 6:52:02 PM UTC+5:30, Anthony wrote:
>>>
>>> and the my show_image function is :
>>>>
>>>> def show_image():
>>>> return response.download(request,dal_db)
>>>>
>>>
>>> That's the problem -- response.download() calls dal.Field.retrieve(),
>>> which assumes the filename is encoded via base64.b16encode (i.e., it
>>> assumes the file was stored using dal.Field.store(), which encodes the
>>> filename). Instead of manually creating the filename, you could use this
>>> procedure: http://web2py.com/books/default/chapter/29/6#Manual-uploads.
>>> Just make the filename exactly what you want the downloaded filename to be
>>> (including the extension), and do the insert into the upload field -- it
>>> should automatically create the encoded name, store the name in the upload
>>> field, and store the image in the blob field. In this case, the image
>>> should be a file stream, and I think fetch will return a string, so you
>>> might need to do:
>>>
>>> import cStringIO
>>> profile_image = cStringIO.StringIO(result.content)
>>>
>>> Anthony
>>>
>>