1

Hoping someone can help cure my stupidity. I am creating a webapp where I need to upload csv files and process them. I am struggling to get my code to work in its simplest form. I can get the page to load up but as soon as I press the submit button to post the file I get a 403 Forbidden Error: Access was denied to this resource.

When I run it in the google app interactive console it does not give me any errors. Can some one point me in the right direction please.

HTML:

{% extends base_layout %}


{% block header_title %}
        {% trans %}Upload Documents{% endtrans %}
{% endblock %}

{% block content %}

  <form action="/upload" method="post" enctype="multipart/form-data">
  <input type="file" name="myfile">
  <br>
  <input type="submit" name="submit" value="Submit">

{% endblock %} 

Handler class:

class Upload(BaseHandler):
    def get(self):
        return self.render_template('upload.html')

    def post(self):

        file = self.request.POST.getall('myfile')

        #file will be process with data going into models here.

        self.response.out.write("success")
1

1 Answer 1

3

You cannot simply upload a file to app engine since the file system is read only. You have to upload to either cloud storage or blob storage. When using either you have to use the facilities for each.

The easiest and fastest way to upload files via a form is with the blobstore api.

Sign up to request clarification or add additional context in comments.

5 Comments

in blobstore example they create the html form in the response handler which does not give me the ability to control where the submit button goes on the actual upload page. how do I do that? I have attempted to use this in the past but I could not find a way around this.
I have no idea how you would do that in python. I guess you should call blobstore.create_upload_url before your return self.render_template('upload.html') and set it as a context variable of sorts. Then you should be able to access the context variable in your template. That would be very similar to the way i'd handle this in Java.
Thank you for your help.
Just wondering do I have to use blobstore if I only want to read the information in the file. I don't really want to store this file just get the information out and put it in to models
Nope you can also create a request handler that accepts multipart/form-data.

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.