Akhil Yeleswar
Akhil Yeleswar

Reputation: 85

Google App Engine Flask 413 Request Entity Too Large Error

I am wondering how to fix this error in google app engine using flask. I understand that a file cannot exceed 32 MB. I am uploading videos and trying to store them in google cloud storage, I need to handle large videos. I have heard that using blobstore api may help but have not found much documentation on this and how I can implement it in this code.

<form id = "form2" action="{{ url_for('createPost') }}" method="POST" enctype="multipart/form-data">
<div class="form-group">
    <label for="files4">Video:</label>
    <input type="file" id="files4" name='files4'>
 </div>
</form>


def createPost():
    if request.method == 'POST':
    s = db.session()
    try:
        files4 = request.files.getlist('files4')
        print(files4)
    except Exception as e:
        print("[Upload] Got exception: %s" % str(e))
    return redirect(url_for('projects'))

Upvotes: 1

Views: 1682

Answers (1)

Alex
Alex

Reputation: 5276

Here are 2 methods by which you can do this via blobstore:

1 - create_upload_url

https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.ext.blobstore.blobstore#google.appengine.ext.blobstore.blobstore.create_upload_url

and here is an example

https://www.programcreek.com/python/example/103205/google.appengine.ext.blobstore.create_upload_url

2 - BlobstoreUploadHandler however this requires you to use webapp2 instead of flask, although you could setup a webapp2 micro-service just for this endpoint

https://cloud.google.com/appengine/docs/standard/python/tools/webapp/blobstorehandlers#BlobstoreUploadHandler

If neither of these methods work, then you'd need to setup an app engine flex micro-service, so that you can edit the nginx conf to all files larger that 32 MB

Upvotes: 2

Related Questions