0
votes

I'm getting the following error when trying to upload an image to a google app engine project using blobstore:

ERROR    2018-10-29 11:18:21,519 user.py:476] ERROR is 'PicUploadHandler' 
object has no attribute '_BlobstoreUploadHandler__uploads'
ERROR    2018-10-29 11:18:21,519 user.py:477] EXC is 'PicUploadHandler' 
object has no attribute '_BlobstoreUploadHandler__uploads'
Traceback (most recent call last):
  File "C:\Users\...\PycharmProjects\...\user.py", line 460, in post
    upload_files = self.get_uploads()[0]  #: 'file' is file upload field in 
the form
  File "C:\Program Files(x86)\Google\google_appengine\google\appengine\ext\webapp\blobstore_handlers.py", line 380, in get_uploads
if self.__uploads is None:
AttributeError: 'PicUploadHandler' object has no attribute '_BlobstoreUploadHandler__uploads'

My code is as follows:

class PicUploadHandler(BaseHandler, blobstore_handlers.BlobstoreUploadHandler):
"""handler to upload a profile photo to the blobstore"""

def get(self):

    try:
        user = self.user_obj()
        if user:
            upload_url = blobstore.create_upload_url('/u/profile-pic-upload')  #: create the upload url
            template_values = {
                'user': user,
                'upload_url': upload_url,
            }
            #: RENDER TEMPLATE
            self.render_template(ROUTE, '/profile-pic-upload.html', template_values)
        else:  
            self.redirect('/')

    except Exception, e:
        logging.error("ERROR is %s" % e)
        logging.exception("EXC is %s" % e)
        self.redirect("/oops")  # unexpected error

def post(self):

    try:
        user = self.user_obj()
        if user:
            self.response.headers['Content-Type'] = 'image/svg+xml'
            if user.pic_key:
                blobstore.delete(user.pic_key)  #: retrieve the old home photo and delete it
            upload_files = self.get_uploads()[0]  #: 'file' is file upload field in the form

            #: update the datastore values for the user's home photo
            user.pic_url = get_serving_url(upload_files.key())
            #: the blobstore key for later retrieval
            user.pic_key = upload_files.key()
            user.put()
            #: redirect to the profile page
            self.redirect('/u/edit-profile/')

    except Exception, e:
        logging.error("ERROR is %s" % e)
        logging.exception("EXC is %s" % e)
        self.redirect("/oops")  # unexpected error

I've copy pasted this code from an older project, where it runs with no errors.

Any help would be much appreciated, thanks.

EDIT: As a Hail Mary, I uploaded the code so as to check the logs from a live instance. It seems the problem is with the dev server/datastore, as the code runs when the app is online. Anyone have an idea why this would be the case?

1
You should log upload_files in your post section. The error is probably due to not having a file where you expect it. - GAEfan
@GAEfan thanks for that. I'm no more than an occasional programmer, doing the odd project for work. The last one was 2 years ago! As such, I'm having no luck fixing this error. If you could give a more specific fix I would really appreciate it. Cheers. - zmdc

1 Answers

0
votes

Try logging to see what you have:

import logging

user = self.user_obj()
if user:
    self.response.headers['Content-Type'] = 'image/svg+xml'
    if user.pic_key:
        blobstore.delete(user.pic_key)  #: retrieve the old home photo and delete it

    logging.error(self.get_uploads())
    logging.error(self.get_uploads()[0])
    upload_files = self.get_uploads()[0]  #: 'file' is file upload field in the form
    ...