Hi everybody,

I manually uploaded file via SQLFORM.factory too and the file has been 
uploaded using the excerpt below :

forma = SQLFORM.factory(
                            Field("image_1", "upload", uploadfield=True, 
uploadfolder=os.path.join(request.folder,'uploads/'), ...), ..., 
table_name="imagebiens")
...
if forma.validate():
        if forma.vars.image_1:
            db.imagebiens.insert(**dict(image=forma.vars.image_1, 
bienid=bien.id))
...
It works. I can find the file renamed in the uploads folder.
But now, I want to render the file in a view like this :

<p>
    {{for sary in limagebien:}}
    <img src="{{=URL("default", "download", args=sary.image)}}" width="96" 
height="96">
    {{pass}}
</p>


which is rendered in html like this :

<p>             <img 
src="/maloca/default/download/imagebiens.image_1.a8e26134c9014d3a.6372756e636862616e672e706e67.png
 
<view-source:http://127.0.0.1:8000/maloca/default/download/imagebiens.image_1.a8e26134c9014d3a.6372756e636862616e672e706e67.png>"
 width="96" height="96">               <img 
src="/maloca/default/download/imagebiens.image_1.b24410c2dae27017.6372756e636862616e672d666c616d65732d776964652d62792d6f6d6e732e6a7067.jpg
 
<view-source:http://127.0.0.1:8000/maloca/default/download/imagebiens.image_1.b24410c2dae27017.6372756e636862616e672d666c616d65732d776964652d62792d6f6d6e732e6a7067.jpg>"
 width="96" height="96">       </p>


The problem is that the image doesn't appear. The download action seems not 
to be capable to render it. Has anyone an idea where in this code the 
problem comes from?

Thanks in advance

Le jeudi 6 octobre 2011 01:55:20 UTC+3, TheSweetlink a écrit :
>
> Hello Alex, 
>
> Two things I've found when manually uploading via SQLFORM.factory: 
>
> 1)  You need to specify a table_name='...' to avoid the 
> no_table_newfilename.extension issue like this: 
>
> form = SQLFORM.factory(...Field definitions..., 
> table_name='some_table_name') 
>
> 2)  Additionally you must specify an uploadfolder in your upload Field 
> definition similar to this: 
>
> form = SQLFORM.factory(..., 
> Field('invoice_logo', type='upload', 
> uploadfolder=os.path.join(request.folder,'static/uploads/')), 
> ..., table_name='whatever_you_like') 
>
> **NOTE** 'static/uploads' is just an example, you can upload to 
> wherever it will be appropriate. 
>
> In this case the newly uploaded and renamed file to 
> your_application's_dir/static/uploads/your_new_filename_here 
>
> One gotcha to look out for following your field name as an example 
> without the quotation marks: 
>
> In your form.accepts(...): 
>
> "request.vars.invoice_logo" will contain the original filename of your 
> upload whereas 
>
> "form.vars.invoice_logo_newfilename" will contain the newly renamed 
> file like yourtablename.9203842903.thaoeu09gu023hgda3p.ext 
>
> No need to call store() directly as SQLFORM.factory will take care of 
> that for you. 
>
> I hope that this helps you. 
>
> -David Bloom 
>
> On Oct 4, 7:53 pm, Alex <mrauc...@gmail.com> wrote: 
> > Hi, 
> > 
> > I've already spent quite some time with the following problem which I 
> > think should be fairly easy. I hope someone can help me. 
> > 
> > # model 
> > db.define_table('admin_setting', 
> >     Field('name', 'string', notnull=True), 
> >     Field('value', 'string', notnull=True)) 
> > 
> > in the controller I'm creating a form for various admin settings. 
> > form = SQLFORM.factory( 
> >         Field('invoice_logo', 'upload'), ...) 
> > 
> > the view works well and displays all fields. 
> > 
> > When uploading a file for the logo the file should be handled like 
> > always (file uploaded to uploads folder, renamed to uuid filename). in 
> > the table admin_setting I want to store the filename of the uploaded 
> > file in a row where name='invoice_logo' (the filename should be stored 
> > in the value field). 
> > 
> > How can I achieve this? currently I have this code (the update is 
> > performed later and not shown here): 
> > if form.accepts(request.vars, formname='admin_setting_form', 
> > dbio=False): 
> >   if request.vars.invoice_logo != None: 
> >     if type(request.vars.invoice_logo) != str: 
> >       request.vars.invoice_logo_filename = 
> > request.vars.invoice_logo.filename 
> >       field = Field('invoice_logo', 'upload') 
> >       # field.store fails because field does not have a _tablename 
> >       uploaded_file = field.store(request.vars.invoice_logo.file, 
> > request.vars.invoice_logo.filename) 
> >     else: 
> >        del request.vars.invoice_logo # do not delete existing logo

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