On Tuesday, August 6, 2019 at 8:21:57 AM UTC-7, Kimus wrote:
>
> olha eu aqui dnv  :) 
>
> Estou com um problema eu insiro uma imagem no banco mas na hr de mostrar 
> no HTML não consigo de jeito nem um, eu nãoi to  usando o template do 
> web2py então td pra mim é mais dificil alguem teria algum jeito de fazer 
>
> OBS : eu coloquei um campo extra_field no auth_user como foto e queria 
> exibir essa foto, só que não utilizo quase nd do que o web2py tem pronto 
> tipo sqlform grid essas coisas dai tenho que fazer mais manual a coisa 
> alguem teria como me dar uma luz 
>
> To tentando algo do genero  tentei usar a função download que ta na 
> default só que no meu controller só que ainda não funciona quando salvo a 
> imagem ela upa a imagem no upload  tipo auth_user.foto e uma hash só qe não 
> consigo fazer funcionar msm alguem me ajuda :( 
>
> <img src="{{=URL(c='template',f='download',args='auth_user.foto.file')}}">
>


An upload field will store the original filename and an obfuscated filename 
(that is, a new name for the file that contains a unique portion and an 
encoding of the original name).  The obfuscated filename, which looks 
rather like a hash, is the filename used by the filesystem.   The 
user/download function in the controllers/default.py understands how to 
handle this.  The URL to download an uploaded file is generated by 

A(" click to download", _href= URL("download", args=row.fdata)
and looks like
download/uploadf.fdata.81a339e105991c67.454e482d3570317670303956505530653369757a394d73484a64465f70657270657475616c5f5352562d48565f323031393038303631373237.txt


Translating this to display an image, here's a controller function:

def testimg():
   row = db(db.uploadf.fname=="test1").select().first()
   return dict(img = row.fdata)

using the model

db.define_table('uploadf', 
                Field('fname', 'string'),
                Field('fdata', 'upload'),migrate='uploadf.table') 

and the view testimg.html looks like

{{extend 'layout.html'}}
{{block header}}
Blah!
{{end}}
{{=IMG(_src=URL("download", img), _alt="test image")}}

After the page is loaded, if you use the browser tools to Inspect Element, 
you're shown

<img alt="test image" src=
"/updater/download/uploadf.fdata.adbba9e59b5e3383.323031392d776f6d656e732d776f726c642d6375702d6461792d32302d353739383430333339333435343038302d6c61772e676966.gif"
>

To connect with your auth_user table, you may want to add an extra field 
that references the file uploaded image.

For more on upload fields, see
<URL:http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Field-types>
<URL:http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#More-on-uploads>
and
<URL:http://web2py.com/books/default/chapter/29/09/access-control#Customizing-Auth>

or 
<URL:http://web2py.com/books/default/chapter/31/06/a-camada-de-abstracao-do-banco-de-dados#-Tipos-de-campo>
<URL:http://web2py.com/books/default/chapter/31/06/a-camada-de-abstracao-do-banco-de-dados#-Mais-sobre-uploads>
and
<URL:http://web2py.com/books/default/chapter/31/09/controle-de-acesso#-Personalizando-Auth>

for the Portuguese (Spanish is "41" instead of "31" or "29").

Good luck!

Dave S
/dps


-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/d35b799d-87a1-4595-b150-68e06168158c%40googlegroups.com.

Reply via email to