spaga
spaga

Reputation: 153

Uploading a file Google App - Python

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")

Upvotes: 1

Views: 49

Answers (2)

Karden Gladden
Karden Gladden

Reputation: 1

Opening the newly uploaded file to process its content.

new_file_path = "/mnt/data/com.google.android.apps.docs.editors.kix.editors.clipboard?uuid=aad6ad1e-b537-452c-9a41-75e2eb3e9208" with open(new_file_path, 'r') as file: new_content = file.read()

new_content

Upvotes: -1

konqi
konqi

Reputation: 5217

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.

Upvotes: 3

Related Questions