Fields of type 'upload' a bit broken in Master

29 views
Skip to first unread message

cdbaron

unread,
Jan 20, 2022, 11:08:17 AM1/20/22
to web2py-users
Hello,

I recently updated an app:
Since web2py Version 2.19.1-stable+timestamp.2020.03.21.13.06.49 and Python 3.6.8
A web2py latest version in Master at the end of 2021 (Version 2.21.2-stable+timestamp.2021.10.15.07.44.23) and python 3.8

Everything seemed to work perfectly.

Now I have noticed that the forms with 'upload' fields are not working well. Actually the form seems to work fine and what doesn't work is the download of the image.

The problem only occurs when I have the following in the routes.py file:
routers = dict(
    BASE=dict(
        default_application='myapp',
    ),
)



In this situation, all requests for uploaded images return a 400 Bad Request error.

With almost all jpg files I have problems, but for example if the image is called ff.jpg it works fine...

I have traced the error to the file gluon.rewrite.py line above line1221:

    def validate_args(self):
        """
        Checks args against validation pattern
        """
        for arg in self.args:
            if not self.router._args_match.match(arg):
                raiseHTTP(
                    400,
                    THREAD_LOCAL.routes.error_message % "invalid request",
                    web2py_error="invalid arg <%s>" % arg,
                )



If I delete the routes.py file everything works fine. But I need myapp as the default app.

Example of the problem with a clean install downloaded from github:

models
db.define_table(
    't_upload',
    Field('f_upload_img', 'upload'),
)


Controller upload.py
def upload_img():
    record = db(db.t_upload).select().first()
    form = SQLFORM(
        db.t_upload,
        record,
        upload=URL('default', 'download')
    )

    if form.process(keepvalues=True).accepted:
        redirect(URL())

    return dict(form=form)



With myapp as default application:
seems to work, but
http://127.0.0.1:8000/download/t_upload.f_upload_img.bba19b6c318b6379.YmwxNTYxODI5Mzg3MTkzNi5qcGc=.jpg
returns 400 bad request



Deleting router.py
http://127.0.0.1:8000/pyapp/upload/upload_img
works fine and
http://127.0.0.1:8000/pyapp/default/download/t_upload.f_upload_img.ae2d38ca06c81a3d.YmwxNTYxODI5Mzg3MTkzNi5qcGc=.jpg
returns the image

Has anyone had this problem?
Reply all
Reply to author
Forward
0 new messages