upload file to rest service on GAE

38 views
Skip to first unread message

James Burke

unread,
Nov 28, 2015, 2:30:51 AM11/28/15
to web2py-users

I'm having some trouble uploading/accessing a file on Google App Engine (GAE).

This is the code used to store the file:

@request.restful()
def workspace():
   
def POST(*args,**vars):
       
        workspace_id
= db.workspace.insert(repository=request.vars.repository,
                                            name
=request.vars.name,
                                            file
=db.workspace.file.store(request.vars.file))
       
from gluon.serializers import json
       
return json(dict(workspace_id=workspace_id))


   
return locals

When I check the field in the Datastore viewer (file_blob) it returns "No data was found".

When I change the above code to:

@request.restful()
def workspace():
   
def POST(*args,**vars):
       
        workspace_id
= db.workspace.insert(repository=request.vars.repository,
                                            name
=request.vars.name,
                                            file
=db.workspace.file.store(request.vars.file))
       
        print '###############'
        print db.workspace(workspace_id).file
        print db.workspace.file.retrieve(db.workspace(workspace_id).file)
        print '###############'

        from gluon.serializers import json
       
return json(dict(workspace_id=workspace_id))


   
return locals

I get the following in the log:

###############

workspace.file.b575903eaa01af0a.6e6f6e65326e6f6e65202831292e666d77.fmw

6051711999279104

ERROR    2015-11-28 07:25:42,062 restricted.py:69]  Unable to store in FILE: /web2py/applications/init/controllers/workspace.py


Traceback (most recent call last):

  File "/web2py/gluon/restricted.py", line 227, in restricted

    exec ccode in environment

  File "/web2py/applications/init/controllers/workspace.py", line 214, in <module>

  File "/web2py/gluon/globals.py", line 412, in <lambda>

    self._caller = lambda f: f()

  File "/web2py/gluon/tools.py", line 3785, in f

    return action(*a, **b)

  File "/web2py/gluon/globals.py", line 378, in f

    return rest_action(*_self.args, **getattr(_self, 'vars', {}))

  File "/web2py/applications/init/controllers/workspace.py", line 128, in POST

    print db.workspace.file.retrieve(db.workspace(workspace_id).file)

  File "/web2py/gluon/packages/dal/pydal/objects.py", line 1544, in retrieve

    raise NotFoundException

NotFoundException


Any help is appreciated.


Cheers,

Reply all
Reply to author
Forward
0 new messages