On Sat, Jan 19, 2013 at 12:12 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

>
> filename=(fileApp.filename.repl**ace(' ', '') if fileApp else '')
>
>
Interesting,

I have tried it before but even it does not work... the error appears
everytime that I enable the validation during the insert... the code that
Bruno posted above

def my_upload():
    import re
    #print request.vars.pic.filename
    fileApp=request.vars.pic
    #print dir(fileApp)
    #filename=fileApp.filename.replace(' ', '')
    filename=(fileApp.filename.replace(' ', '') if fileApp else '')
    #filename='test.jpg'
    result=''
    http_host=''

    #Prevent special caracters in the file name
    expression='[*+~$&^#@!;:,|]'
    regex = re.compile(expression)
    if regex.search(filename):
        result="Special caracters NO!!! Nothing to do..."
        return response.json('<div class="error_wrapper"><div
id="title__error" class="error" style="display:
inline-block;">'+result+'</div></div>')

    aux=db.files.file_upload.store(fileApp, filename)
    #db.files.insert(file_upload=aux,title=filename) *# USING THIS LINE IT
WORKS *
    
*db.files.validate_and_insert(file_upload=db.files.file_upload.store(fileApp,
filename),title=filename)* # *THIS LINE CAUSES THE ERROR
*
    if request.env.http_x_forwarded_host:
        http_host = request.env.http_x_forwarded_host.split(':',1)[0]
    else:
        http_host = request.env.http_host


    last = db().select(db.files.ALL)[-1]
    result=T('Successfuly! Here the link: ')
    result+="<a href=http://
"+http_host+'/'+request.application+'/'+request.controller+'/download/'+last.file_upload+">Download</a>"

    return response.json('<div class="alert alert-success">'\
            +result+\
            '</div>')

186.214.187.119.2013-01-19.12-53-48.0336b24c-763e-4a83-bff2-50de3905d280
<type 'exceptions.AttributeError'> 'NoneType' object has no attribute 'name'
Versão  web2py™ (2, 3, 2, datetime.datetime(2012, 12, 17, 15, 3, 30),
'stable')  Python Python 2.7.3: /usr/local/bin/uwsgi  Traceback


1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.


Traceback (most recent call last):
  File "/home/titogarrido/web2py/gluon/restricted.py", line 212, in restricted

    exec ccode in environment
  File "/home/titogarrido/web2py/applications/cms/controllers/default.py"
<https://titogarrido.pythonanywhere.com/admin/default/edit/cms/controllers/default.py>,
line 118, in <module>

  File "/home/titogarrido/web2py/gluon/globals.py", line 193, in <lambda>

    self._caller = lambda f: f()

  File "/home/titogarrido/web2py/applications/cms/controllers/default.py"
<https://titogarrido.pythonanywhere.com/admin/default/edit/cms/controllers/default.py>,
line 100, in my_upload

    aux=db.files.file_upload.store(fileApp, filename)

  File "/home/titogarrido/web2py/gluon/dal.py", line 8601, in store

    filename = file.name
AttributeError: 'NoneType' object has no attribute 'name'




-- 

Linux User #387870
.........____
.... _/_õ|__|
..º[ .-.___.-._| . . . .
.__( o)__( o).:_______

-- 



Reply via email to