1
votes

I've recently deployed my python GAE app from the development server and my image upload function stopped working properly...

After a bit of testing, it seems that the get_uploads function from blobstore is returning an empty list and hence I get an out of index error from the upload handler (also tried the get_file_infos function and had the same result)

However, when I check the GCS browser, the file is properly uploaded so my problem seems to be that I can't find a way to extract the image link from the post to Upload Handler

Anybody have clues as to why this is happening? and if there's a way around this?

(The form uses a post method with multipart/form-data so hopefully that isn't an issue)

  • Here's the function I'm calling to post to the upload handler:

    upload_url = blobstore.create_upload_url('/upload', gs_bucket_name='BUCKET')
    result = urlfetch.fetch(url= upload_url,
                            payload=self.request.body,
                            method=urlfetch.POST,
                            headers=self.request.headers)
    
  • And here's the code for the upload handler:

    class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
        def post(self):
            upload_files = self.get_uploads('file')
            blob_info = upload_files[0]
            self.response.write(str(blob_info.key()))
    
1

1 Answers

2
votes

What do you try to do?

It looks like you try to post a received body to GCS. Why not write it using the Google Cloud Storage Client Library.

with gcs.open(gcs_filename, 'w', content_type, options={b'x-goog-acl': b'public-read'}) as f:
    f.write(blob)