Get the current user from BlobstoreUploadHandler(从 BlobstoreUploadHandler 获取当前用户)
问题描述
I want to get the current user from BlobstoreUploadHandler. I'm using endpoints for my web application, but (outside of Endpoints) I built /uploadUrl to upload files to the Blobstore.
The image uploads correctly. So, I need to link the image uploaded to the user, but users.get_current_user() returns None. On the frontend side the user is logged using OAuth2. Any idea for this issue?
If I use endpoints.get_current_user() raise an error:
No valid endpoints user in environment
This is my 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 its own login, and every class needs to have users imported and declared if you want to use User class in the 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 this article - https://cloud.google.com/appengine/docs/python/users/
这篇关于从 BlobstoreUploadHandler 获取当前用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 BlobstoreUploadHandler 获取当前用户


- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- 沿轴计算直方图 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01