Didn't Massimo already solve this for 
you: https://groups.google.com/d/msg/web2py/YlGv7Ap1HVA/AkEyDkUr-FAJ

First, your onvalidation function stores the file using the field's 
.store() method. Then it assigns the resulting filename to form.vars.photo, 
which presumably is an upload field. Subsequently, the .accepts() method 
attempts to store the contents of form.vars.photo in a file as well (it is 
expecting form.vars.photo to be the uploaded file at that point, not a 
filename) -- hence the second file, which contains the name of the first 
file.

Anthony

On Thursday, January 17, 2013 8:50:25 AM UTC-5, Ramos wrote:
>
> hello
> i have a strange behaviour in my sqlform
>
> def attach_image_to_record(form):
>
>     if form.vars.delete_this_record not in ['on']:
>
>         response=requests.get(form.vars.fp_url)
>         img=Image.open(StringIO(response.content))
>         img.save('foto1231.jpg','JPEG')
>         temp=open('foto1231.jpg','rb')
>         foto=db.trabalhador.foto.store(temp,'foto.jpg')
>         print "print new foto",foto   # this prints something like 
> trabalhador.foto.123o817.asdasdaid.jpg
>         form.vars.foto=foto
>
>
> if trabalhador_form.process(onvalidation=attach_image_to_record).accepted:
>     print "trab foto",trabalhador_form.vars.foto  
> # this prints something like 
> trabalhador.foto.987398734982734.12312o319832789.txt
>
> in my upload folder i see the 2 files.
> The txt inside has writen the name of the image file above
>
> Why?
>
> Thank you
>
>
>

-- 



Reply via email to