Python 2.7 从app engine将文件上载到google云存储

Python 2.7 从app engine将文件上载到google云存储,python-2.7,google-app-engine,google-cloud-platform,google-cloud-storage,Python 2.7,Google App Engine,Google Cloud Platform,Google Cloud Storage,我能够用下面来自谷歌应用程序引擎的代码将小文件写入谷歌云存储。当我试图写更大的文件时,内存异常 我的想法可能是,它先写入整个文件内存,然后再写入谷歌云存储。我有没有办法一块一块地下载并一块一块地写入谷歌云存储。还是这个问题完全不同 def _writeFilesinGCS(filename, data): ### Initializing Google cloud Storage Object print "In _writeFilesinGCS function" tmp_file

我能够用下面来自谷歌应用程序引擎的代码将小文件写入谷歌云存储。当我试图写更大的文件时,内存异常

我的想法可能是,它先写入整个文件内存,然后再写入谷歌云存储。我有没有办法一块一块地下载并一块一块地写入谷歌云存储。还是这个问题完全不同

def _writeFilesinGCS(filename, data):
  ### Initializing Google cloud Storage Object
  print "In _writeFilesinGCS function"
  tmp_filenames_to_clean_up = []
  write_retry_params = _gcs.RetryParams(backoff_factor=1.1)
  gcs_file=_gcs.open(filename, 'w', content_type='text/plain',retry_params=write_retry_params)
  gcs_file.write(data.encode('utf-8'))
  gcs_file.close()
  tmp_filenames_to_clean_up.append(filename)

def download_files(service, report_run_id, report_fragment,loaddate,file_name,cfg):
  """Generate and print sample report.

  Args:
    service: An authorized Doublelcicksearch service.
    report_id: The ID DS has assigned to a report.
    report_fragment: The 0-based index of the file fragment from the files array.
  """
  bucket_name = cfg._gcsbucket
  bucket = '/' + bucket_name
  filename = bucket + '/' + file_name + "_"+ loaddate + "_MMA_" + loaddate + ".csv"
  print "Enter into download_files", report_run_id
  request = service.reports().getFile(reportId=report_run_id, reportFragment=report_fragment)
  _writeFilesinGCS(filename,request.execute())
  dsbqfuns._dsbqinsert(report_run_id,cfg,file_name,1)

您希望将文件直接发送到GCS存储,而不使用GAE作为中间人:
dsbqfuns.\u dsbqinsert()
做什么?除了向地面军事系统写入数据……更大的文件意味着什么?
report\u fragment
表示的文件片段有多大?(旁注:您的GCS写入也需要考虑到这一点,当前同一文件的片段会相互覆盖)我想将该文件直接存储在GCS中。Python脚本正在google app engine应用程序中运行。dsbqfuns.\u dsbqinsert()只是在bigquery中插入一个条目以记录日志。更大的文件意味着service.reports()。getFiles是下载非常大的文件(5GB)