使用 TextIO.write 到 Google 云存储时如何设置文件类型

How to set file type when using TextIO.write to Google Cloud Storage

我写了一个 DataFlow 管道,它在 Google 云存储上输出一个小的 csv 文件。该文件的文件类型是 text/plain 但我希望它是 application/csv.

这是我使用的代码

TextIO.write()
.to("gs://bucket/path/to/filename").withoutSharding()
.withSuffix(".csv")
.withDelimiter(new char[]{'\r','\n'})

如何指定文件类型,以便在管道完成后文件类型为 application/csv

TextIO 始终写入内容类型 text/plain。这是在这里配置的。 https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TextSink.java#L95

您的一个选择可能是更新已写入 GCS 的对象的内容类型。这可以在完成写入文件的数据流管道后使用 gsutil 工具完成。浏览此处获取更多信息。 https://cloud.google.com/storage/docs/gsutil/commands/setmeta