On Tuesday, March 29, 2016 at 2:28:13 PM UTC-7, Nick Michael wrote:
>
> Hi, I'm having some trouble and was hoping someone could point me in the 
> right direction.
>
> I'm creating an application which has an input form which stores to a 
> database. One entry accepts images, but can also be left empty (by using 
> requires IS_EMPTY_OR). I also have a placeholder image saved under 
> 'static/images'. I want to make it so that if the upload file is left 
> empty, I store the placeholder image from the 'static/images' folder in the 
> database entry, otherwise it'll use the image that was uploaded by the user.
>
>
Do you really need to store the image in the DB?  If the same placeholder 
is used for everyone (until they upload), just having a flag saying "use 
placeholder" might be enough.  Also, a normal upload field is a filename 
(the obfuscated one); you could put the static path in the field.  In 
either case, download() changes from the example code to checking either 
the flag or the path to see where to get the image to stream.

If you are using something other than a "normal upload" field, please show 
your model.

/dps


 

> Here's my current implementation:
>
> if request.vars.image == "":
>         ##----Enter Code Here----##
> else:
>     image_file = db.user_items.image.store(request.vars.image.file, 
> request.vars.image.filename)
> addItemToData (request.vars.name, request.vars.collection, 
> request.vars.tag, request.vars.value, request.vars.story, image_file, 
> auth.user.id, request.vars.tradeable)
> redirect(URL('default', 'profile'))
>

-- 
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