如何使用python将数据从gzip文件写入GCS存储桶

时间:2021-03-26 10:55:55

标签: python google-cloud-platform

我正在尝试读取 gzip 文件并将相同的数据以解压缩格式放入 GCS 中。我能够读取数据,但无法以解压缩格式将其放入存储桶中。任何人都可以帮我解决这个问题。下面是代码。变量“res”有来自压缩文件的数据

blob = bucket.blob('sftp/poc/TEST_3.dat.gz')
downloaded_blob = blob.download_as_bytes()
print(downloaded_blob)
buff = BytesIO (downloaded_blob) # put    content into file object
f = gzip.GzipFile(fileobj=buff)
print('Lots    of content here 8')
res = f.read().decode('utf-8')
print(res)

最后一条语句给了我以下数据

header1
abc,xyz,pqr

我想将这些数据放在存储桶中的单独文件中

我尝试使用语句,但错误太多:

blob.upload_from_string(res,content_type='text')


error
    message": "Provided CRC32C \"TjQbeA==\" doesn't match calculated CRC32C \"tDXRSA==\".",
    "message": "Provided MD5 hash \"hUglr3YB9TbhejPDdOAaYA==\" doesn't match calculated MD5 hash \"qk5UY/FTXa8asu8/KZFyDA==\".",
    "message": "Content-Type specified in the upload (text) does not match Content-Type specified in metadata

0 个答案:

没有答案