【问题标题】:google cloud storage stores only (48 B) for each file谷歌云存储仅为每个文件存储 (48 B)
【发布时间】:2016-06-23 22:34:24
【问题描述】:

我正在使用 html <form> 将二进制 jpeg 文件上传到我在 Google App Engine 上托管的 python webapp 服务器。服务器方法接收整个图像(已成功尝试打印文件大小/类型等统计信息),但无法将其写入谷歌云存储桶。最终在 GCS 存储桶上的是一个只有 48 字节的损坏文件。

def handleUpload(self):

  client = self._get_storage_client()
  bucket = client.get_bucket(config.CLOUD_STORAGE_BUCKET)

  results = []

  for name, fieldStorage in self.request.POST.items():
    if type(fieldStorage) is unicode:
      continue
    result = {}
    fileName = urllib.unquote(fieldStorage.filename)
    blob = bucket.blob(fileName)

    blob.upload_from_string(
        str(fieldStorage.file),fieldStorage.type)

    url = blob.public_url
    if isinstance(url, six.binary_type):
        url = url.decode('utf-8')

    results.append(result)

  return results

【问题讨论】:

    标签: python-2.7 google-app-engine google-cloud-storage gcloud-python google-cloud-python


    【解决方案1】:

    想通了。实际上它应该是 fieldStorage.file.read() 而不是 fieldStorage.file 因为它使用临时缓冲区而不是一次读取整个文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 2016-10-12
      • 1970-01-01
      • 1970-01-01
      • 2020-09-10
      • 2018-05-31
      相关资源
      最近更新 更多