python - Get the current user from BlobstoreUploadHandler -
i want current user blobstoreuploadhandler. i'm using endpoints web application, (outside of endpoints) built /uploadurl upload files blobstore.
the image uploads correctly. so, need link image uploaded user, users.get_current_user() returns none. on frontend side user logged using oauth2. idea issue?
if use endpoints.get_current_user() raise error:
no valid endpoints user in environment
this code:
class uploadhandler(blobstore_handlers.blobstoreuploadhandler): def post(self): upload_files = self.get_file_infos() file_info = upload_files[0] gcs_filename = file_info.gs_object_name file_key = blobstore.create_gs_key(gcs_filename) file(file=gcs_filename, owner=users.get_current_user() ).put()
each app requires own login, , every class needs have users imported , declared if want use user class in code.
from google.appengine.api import users import webapp2
class myhandler(webapp2.requesthandler): def get(self): user = users.get_current_user() if user: greeting = ('welcome, %s! (<a href="%s">sign out</a>)' % (user.nickname(), users.create_logout_url('/'))) else: greeting = ('<a href="%s">sign in or register</a>.' % users.create_login_url('/')) self.response.out.write('<html><body>%s</body></html>' % greeting)
for more details please see article - https://cloud.google.com/appengine/docs/python/users/
Comments
Post a Comment