Appengine Blobstore:指数超出范围

时间:2014-12-05 17:07:27

标签: python google-app-engine google-cloud-platform google-cloud-storage google-cloud-python

我正在尝试使用Blobstore API将文件上传到Google云端存储。图像上传正确,但后来我尝试处理它(将其链接到用户)。我收到了错误:

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]行。

1 个答案:

答案 0 :(得分:1)

将文件放入Google云端存储分区的代码在哪里?

我认为问题可能是这两行,具体取决于您实施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云端存储配合使用,请参阅此文章了解详情 - https://cloud.google.com/appengine/docs/python/blobstore/#Python_Using_the_Blobstore_API_with_Google_Cloud_Storage