I've been trying relentlessly to display a photo that is connected to a user. I've tried the download function a thousand ways and am slowly running out of Google search terms. Here is what I've tried:
<db.py>
auth.settings.extra_fields[auth.settings.table_user_name]=
[Field('picture','upload')] #success, no hiccups
</db.py>
<default.py>
def get_file():
row = db(db.auth_user.id==request.args(0)).select().first()
return locals() #success, no hiccups
row =db(db.auth_user.id)...
def download()
return response.download(request,db)
</default.py>
<get_file.html>
<img src="{{=URL('download',args=db.auth_user.picture)}}/>
#displays broken image
#other failed methods
{{for b in row:}}<img...args=b.picture>{{pass}}
{{for...args=b...}}
#also used for loop to print out username. That worked, but when I tried image it displayed a link. When I added img tags before the link I got a broken link
<h2>{{=row.picture}}</h2>
<h2>{{row.picture}}</h2>
<h2>{{db.auth_user.picture}}</>
#same thing with equal sign before db
</get_file.html>
Everything has failed me or caused me a ticket thus far. I'm out of creative ideas and am looking for another thousand ideas to try before I have to start translating my searches to Italian and Spanish.
Thanks for reading! Awaiting your response.
<get_file.html><img src="{{=URL('download',args=db.auth_user.picture)}}/>
#displays broken image
#other failed methods
{{for b in row:}}<img...args=b.picture>{{pass}}
#also used for loop to print out username. That worked, but when I tried image it displayed a link. When I added img tags before the link I got a broken link
<h2>{{=row.picture}}</h2>
<h2>{{row.picture}}</h2>
<h2>{{db.auth_user.picture}}</>
users = db(db.auth_user).select() # pass this to the view
{{for user in users:}}
<img src="{{=URL('default', 'download', args=user.picture)}}">
{{pass}}
I should probably clarify more. The dots are just my shorthand way of indicating that the code is the same in that spot and the only thing that changed was what I typed out the following time.
The b in the for loop is just a variable that indicates the same value as your "user"
Typed out it would be:
{{for b in row:}}<img src="{{URL('default','download',args=b.picture)}}"
I'm aware of the documented way,but it wasn't working for me so I tried various things in vain of course.
I'll definitely erase what I have tried so far and try what you suggested though. Be back shortly!
{{for b in row:}}<img src="{{URL('default','download',args=b.picture)}}"
I didn't figure exactly what I wanted, but I just added a require in the model that limits the width and height
I'm on my laptop now trying the jsfiddle code. Nothing is happening. I suspect it may be the link I created. What do you think?
Link in html:
<link href="{{=URL('static', 'css/style.css')}}" rel="stylesheet" type="text/css"/>
I created a static named style.css an it appears at the bottom of the static file.
Css:
.container{
display:flex;
justify-content:center;
flex-wrap:wrap;
align-items:center;
}
img{
width:100%;
max-width:200px;
}
Let me know if there's anything else you need!
I'm on my laptop now trying the jsfiddle code. Nothing is happening. I suspect it may be the link I created. What do you think?
Link in html:
<link href="{{=URL('static', 'css/style.css')}}" rel="stylesheet" type="text/css"/>I created a static named style.css an it appears at the bottom of the static file.
Css:
.container{
display:flex;
justify-content:center;
flex-wrap:wrap;
align-items:center;
}
var cropperCanvas = this.cropper.getCroppedCanvas();
var tmpCanvas = document.createElement('canvas');
tmpCanvas.width = 540; // target width
tmpCanvas.height = cropperCanvas.height * tmpCanvas.width / cropperCanvas.width; // same ratio
var ctx = tmpCanvas.getContext("2d");
ctx.drawImage(cropperCanvas, 0, 0, cropperCanvas.width, cropperCanvas.height, 0, 0, tmpCanvas.width, tmpCanvas.height);
hiddenInputEl.value = tmpCanvas.toDataURL(); // input type="hidden" for final upload to the server