Even better:
uploadfolder=os.path.join(request.folder, 'uploads', 'profiles')
os.path.join automatically uses the correct path separator for your OS.
Anthony
On Saturday, December 8, 2012 3:24:52 PM UTC-5, Paolo Caruccio wrote:
>
> please try :
>
> import os
> db.define_table('tutor',
> Field('user', 'reference auth_user', default=auth.user_id),
> Field('t_Image', 'upload', uploadfolder=os.path.join(request.folder,
> 'uploads/profiles'), requires=IS_EMPTY_OR(IS_IMAGE(extensions=('jpeg',
> 'jpg', 'png', 'gif')))),
> Field('t_Location', 'list:string', requires=IS_NOT_EMPTY()),
> Field('t_Subjects', 'list:string', requires=IS_NOT_EMPTY()),
> Field('t_Qualifications', 'list:string', requires=IS_NOT_EMPTY()),
> Field('t_Biography', 'text'), #Does this need to be sanitized?
> Field('t_Hourly_Rate', 'decimal(7,2)', requires=IS_NOT_EMPTY()),
> Field('t_Modified_On', 'datetime', requires=IS_DATETIME(), writable=
> False, readable=False, default=request.utcnow)
> )
>
>
>
> Il giorno sabato 8 dicembre 2012 18:58:45 UTC+1, Daniele ha scritto:
>>
>> This is still not working for me and I can't figure out for the life of
>> me how to do this simple uploading and displaying of an image.
>>
>> I now have a table dedicated to tutors, which looks like this:
>>
>> db.define_table('tutor',
>> Field('user', 'reference auth_user', default=auth.user_id),
>> Field('t_Image', 'upload', uploadfolder='uploads/profiles',
>> requires=IS_EMPTY_OR(IS_IMAGE(extensions=('jpeg', 'jpg', 'png', 'gif')))),
>> Field('t_Location', 'list:string', requires=IS_NOT_EMPTY()),
>> Field('t_Subjects', 'list:string', requires=IS_NOT_EMPTY()),
>> Field('t_Qualifications', 'list:string', requires=IS_NOT_EMPTY()),
>> Field('t_Biography', 'text'), #Does this need to be sanitized?
>> Field('t_Hourly_Rate', 'decimal(7,2)', requires=IS_NOT_EMPTY()),
>> Field('t_Modified_On', 'datetime', requires=IS_DATETIME(),
>> writable=False, readable=False, default=request.utcnow)
>> )
>>
>> I then have the following in my controller:
>>
>> @auth.requires_login()
>> def edit_profile():
>> response.subtitle = T("Edit Profile")
>>
>> tform = SQLFORM.factory(
>> Field('is_tutor', 'boolean'),
>> *[f for f in db.tutor if f.name.startswith('t_')],
>> upload=URL('download'),
>> table_name='tutor')
>>
>> if tform.process(keepvalues=True).accepted:
>> if tform.vars.is_tutor:
>> if not auth.has_membership('Tutors'):
>> auth.add_membership('Tutors')
>> db.tutor.update_or_insert(db.tutor.user==auth.user_id,
>> t_Hourly_Rate = tform.vars.t_Hourly_Rate,
>> t_Image = tform.vars.t_Image,
>> t_Qualifications = tform.vars.t_Qualifications,
>> t_Subjects = tform.vars.t_Subjects,
>> t_Location = tform.vars.t_Location,
>> t_Biography = tform.vars.t_Biography
>> )
>> else:
>> if auth.has_membership('Tutors'):
>> auth.del_membership('Tutors')
>> response.flash = T('Profile updated!')
>> elif tform.errors:
>> response.flash = T('There was an error with your submission')
>>
>> return dict(tform=tform)
>>
>> However, I am not able to display the image. I don't know why I can't do
>> something so simple -_-....
>> Any help is greatly appreciated.
>>
>> Daniele
>>
>>
>>
>> On Wednesday, December 5, 2012 2:06:57 PM UTC, Daniele wrote:
>>>
>>> Guys I know this sounds simple but I'm having a hard time displaying
>>> uploaded images. I have an upload field in my model where logged in users
>>> can upload an image. But in my views when I try to do
>>> {{=IMG(_src=URL('uploads/', row.image))}} where row is a variable that
>>> refers to db(db.auth_user.id > 0).select() nothing is being returned.
>>> However, row.image returns a string which is the name of the file.
>>> How can I display the image correctly?
>>>
>>> Thanks!
>>>
>>
--