0

Client side (javascript) uploads the application with XMLHttpRequest:

  var req = new XMLHttpRequest();
  req.open('POST', my_app_url, false);
  req.setRequestHeader("Content-Length", req.length);
  req.sendAsBinary(req.binary);

I use datastore on the server side (not blobstore). How can I save uploaded file to the datastore? I've found that ServletFileUpload can be used with Java. But how to do the same with Python?

2 Answers 2

3

You should use self.request.body

class YourUploadHandler(webapp.RequestHandler):
    def post(self):
        your_binary_content = self.request.body
Sign up to request clarification or add additional context in comments.

Comments

0

If you mean on the appengine side, you just have to have a blobproperty. So something like...

class SomeEntity(db.Model):
    file_data = db.BlobProperty()

class AddData(webapp.RequestHandler)
    def post(self):
        data = self.request.get("filedata")
        e = SomeEntity(file_data = db.Blob(data))
        e.put()

As a note, I'm not sure if the code you posted above to send the request is correct, but you can upload the file with a simple html form, something like this:

<form action="/url_to_adddata_handler/" method="post">
    <input type="file" name="filedata">
    <input type="submit" value="Submit">
</form>

1 Comment

I don't have the form. So I cannot use self.request.get("filedata"), but looks like self.request.body does what I need ;).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.