Yebach
Yebach

Reputation: 1691

web2py view error

I am new to web2py and I have to write a file upload script.

now searching trough internets i found a script and it kind of works local on my cmp After putting it to server i get invalid view (uploda_zipa/upload_file.html)

The code is:

  import datetime



  timestamp = datetime.datetime.today()
                db.define_table('files',
                Field('title', 'string'),
                Field('uploaded_data', 'upload'),
                Field('created_on','datetime',default=timestamp))

  db.files.title.requires = IS_NOT_EMPTY()                
  db.files.uploaded_data.requires = IS_NOT_EMPTY()
  #Now, lets add an action the our controller

  def upload_file():
    url = ""

    form = SQLFORM(db.files, showid=False)
    if form.accepts(request.vars, session):
       response.flash = T('File uploaded successfully!')
       url = URL(r=request, f="download", 
             args = db(db.files.title ==   request.vars.title).select(orderby=~db.files.created_on)[0].uploaded_data)

    return dict(form=form, cknum=request.vars.CKEditorFuncNum, url=url)

I would also like to know how to set path for folder in which files should be uploaded or is that default way. The plan is smth like a file gets uploaded to a specific folder and than it gets processed by a different script

thank you

Upvotes: 1

Views: 997

Answers (1)

Anthony
Anthony

Reputation: 25536

If you do not have an 'upload_file.html' view defined, web2py will fall back to using the 'generic.html' view. However, by default, the generic views are only enabled on localhost, so that probably explains why it worked on your local computer but not once uploaded to the server. For security reasons, it is recommended that you not enable generic views on production, or at least that you do so judiciously. See here for more details.

As for the upload folder, it defaults to /yourapp/uploads, though you can change it as follows:

import os
db.define_table('files',
    Field('uploaded_data', 'upload',
        uploadfolder=os.path.join(request.folder, 'path', 'to', 'uploads')))

See the explanation of uploadfolder in the list of arguments to Field().

Upvotes: 2

Related Questions