Upload size:
In Javascript it is possible read the height/width/size of the image and if 
they are to large, then you can resize them.
No special library is needed. This can be done using html5 canvas.

Here is my code.
The first line of code is from work with js cropper 
https://fengyuanchen.github.io/cropperjs/, where user can crop part of the 
image.
However without a cropper or any existing canvas (i.e. cropperCanvas in 
following code)) I think you can make a additional hidden element and fill 
it with the image using html5 FileReader. From such element attributes you 
can know width/height/size and you can decide, if you call the javascript 
resize (i.e. next code) or if you upload the file as is.

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


I have implemented this in CherryPy so I have no idea about Web2py specific 
problems.

I think you need read Web2py book how to add the additional hidden 
element/canvas (in the template? before the template by manipulating the 
SQLFORM?)
Then in JavaScript you need some input element event (blur?) to fill the 
canvas with html5 FileReader.
As last thing you need read a Web2py book about hidden elements - how to 
add the hiddenInputEl to form data (because I think hidden elements are 
excluded from the validation/saving by default).




On Saturday, 15 October 2016 09:20:41 UTC+2, Jaimee S wrote:
>
> Hello all,
>
> 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.
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to