gpt4 book ai didi

python - Appengine Blobstore : Index out of range

转载 作者:太空宇宙 更新时间:2023-11-04 05:56:50 24 4
gpt4 key购买 nike

我正在尝试使用 Blobstore API 将文件上传到 Google Cloud Storage。图片上传正确,但随后我尝试处理它(将其链接到用户)。我收到错误:

Index out of range

这是我的代码:

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_file_infos('file') # 'file' is file upload field in the form
file_info = upload_files[0]

#self.response.headers['Content-Type'] = 'application/x-www-form-urlencoded'
#self.response.headers.add_header('Access-Control-Allow-Origin', '*')
gcs_filename = file_info.gs_object_name
file_key = blobstore.create_gs_key(gcs_filename)

File(file=file_key, owner=utils.get_current_user(),
url= images.get_serving_url(file_key)).put()

我的代码放在 file_info = upload_files[0] 行。

最佳答案

将文件放入 Google Cloud Storage 存储桶的代码在哪里?

我认为问题可能出在这两行,具体取决于您如何实现 GCS 上传...

gcs_filename = file_info.gs_object_name
file_key = blobstore.create_gs_key(gcs_filename)

如果项目来自 GCS,gs_object_name 应该只返回有意义的结果。如果 gcs_filename 不正确,这也会导致 create_gs_key() 失败。

关于如何将 blobstore API 与 Google Cloud Storage 结合使用,请参阅本文了解详情 - https://cloud.google.com/appengine/docs/python/blobstore/#Python_Using_the_Blobstore_API_with_Google_Cloud_Storage

关于python - Appengine Blobstore : Index out of range,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27321118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com