1
votes

I just follow GAE's document (https://developers.google.com/appengine/docs/python/blobstore/#Python_Uploading_a_blob) to write upload handler to upload blobstore, when I select one file on computer and click Submit button on HTML page, it will show 'The url "/upload" does not match any handlers.' Any comments is appreciated.

class MainPage(webapp2.RequestHandler):
    def get(self):

        self.response.headers['Content-Type'] = 'text/html; charset=utf-8'

        upload_url = blobstore.create_upload_url('/upload')
        logging.info(upload_url)

        self.response.out.write('<html><body>')
        self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url)
        self.response.out.write("""Upload File: <input type="file" name="file"><br> <input type="submit"
            name="submit" value="Submit"> </form></body></html>""")

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):

    def post(self):
        logging.info('Upload handler')
        upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        logging.info(upload_files)
        self.redirect('/serve/%s' % blob_info.key())


class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):

    def get(self, resource):
        resource = str(urllib.unquote(resource))
        logging.info(resource)
        blob_info = blobstore.BlobInfo.get(resource)
        self.send_blob(blob_info)


application = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/upload', UploadHandler),
    ('/serve/([^/]+)?', ServeHandler),
], debug=True)

[Update1] After I click submit button, I check dev-server Blobstore Viewer, I found the file has been uploaded there, however, my chrome browser still show 'The url "/upload" does not match any handlers.'. This is why?

1
What's in the handlers part of your app.yaml? Is there anything mapping /upload to this python module? - Greg
@Greg app.yaml only has one hanlder. - url: / script: AppWS.application - Jerry YY Rain
One more strange thing, In dev server log, there is no any logging.info('Upload handler') information, it seems my UploadHandler has not been called, however, file is uploaded to dev server blobstore, and upload URL is always (localhost:8080/_ah/upload/…) what happened? - Jerry YY Rain

1 Answers

0
votes

I want to ask my question by self that maybe someone encounter similar issue as me.

After I change from

- url: /
  script: AppWS.application

to

- url: (/.*)*
  script: AppWS.application

everything is OK.