¿Cómo modificar blobstoreuploadhandler para admitir el estado 200?

It's said that GAE SDK 1.5.4 has removed the requirement that blobstoreuploadhandler must return a redirect and on production it's supposedly already so that the handler can make a "regular" response to a template with template variables. I need this capability with dev_appserver and therefore ask how I can modify the dev_appserver to admit the handler to render a template with template variables. I suppose that code I need to change is in the file http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/tools/dev_appserver_blobstore.py but I'm not sure what to modify. Can you tell me how to make the handler capable of a regular response?

  def EndRedirect(self, redirected_outfile, original_outfile):
      """Handle the end of upload complete notification.

      Makes sure the application upload handler returned an appropriate status
      code.
      """
      response = dev_appserver.RewriteResponse(redirected_outfile)
      logging.info('Upload handler returned %d', response.status_code)

      if (response.status_code in (301, 302, 303) and
          (not response.body or len(response.body.read()) == 0)):
        contentless_outfile = cStringIO.StringIO()


        contentless_outfile.write('Status: %s\n' % response.status_code)
        contentless_outfile.write(''.join(response.headers.headers))
        contentless_outfile.seek(0)
        dev_appserver.URLDispatcher.EndRedirect(self,
                                                contentless_outfile,
                                                original_outfile)
      else:
        logging.error(
            'Invalid upload handler response. Only 301, 302 and 303 '
            'statuses are permitted and it may not have a content body.')
        original_outfile.write('Status: 500\n\n')

Update: The solution was posted at this link https://groups.google.com/forum/#!topic/google-appengine-python/vnvhUG1-UN0

preguntado el 27 de agosto de 11 a las 20:08

Can you not just wait for 1.5.4, or test in production in the meantime? -

Did you try just adding 200 to the list (301, 302, 303)? -

Thanks for replying. Yes I can wait. And yes I tried just adding 200 to the list and that didn't do it so maybe it's not trivial and instead better to work on my own code and just keep 2 versions of the method I want to upgrade (it was a messy class I'm getting help with at codereview.stack...) I can just wait for 1.5.4 or test in production. -

Please post the solution as an answer, and accept it. -

1 Respuestas

The solution was posted and I could verify that this worked:

def EndRedirect(self, dispatched_output, original_output):

"""Handle the end of upload complete notification. Makes sure the application upload handler returned an appropriate status code. """

    response = dev_appserver.RewriteResponse(dispatched_output)

    logging.info('Upload handler returned %d', response.status_code)
    outfile = cStringIO.StringIO()
    outfile.write('Status: %s\n' % response.status_code)

    if response.body and len(response.body.read()) > 0:
      response.body.seek(0)
      outfile.write(response.body.read())
    else:
      outfile.write(''.join(response.headers.headers))

    outfile.seek(0)

dev_appserver.URLDispatcher.EndRedirect(self,outfile,original_output)

Respondido el 07 de Septiembre de 11 a las 09:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.