使用 Google 云存储库在 Google 存储桶中移动 blob
Move blob within Google bucket using Google Cloud Storage library
我有一个 Spark 作业,我想在其中使用 google.cloud.storage.StorageOptions
将 Google Cloud Storage 存储桶中的文本文件从目录 A 移动到目录 B
源文件路径 = "gs://spark-bucket/directoryA/subdirectoryA/textfile.txt"
dest bucket location = "gs://spark-bucket/directoryA/subdirectoryB/"
sourceBucketName、blobName 和 destBucketName 应该是什么?是否必须是完整路径“gs://spark-bucket/directoryA/subdirectoryA/”或只是存储桶名称,即基于上述源文件路径的“spark-bucket”?
val storage = StorageOptions.newBuilder.setProjectId("project-id").build.getService
val blobId = BlobId.of(sourceBucketName, blobName)
val blob = storage.get(blobId)
val copyWriter = blob.copyTo(destBucketName, destBlobName)
blob.delete();
您想将 textfile.txt
从 gs://spark-bucket/directoryA/subdirectoryA/
移动到 gs://spark-bucket/directoryA/subdirectoryB/
从你的问题可以看出你只有一个桶,即 spark-bucket。所以 sourceBucketName 和 destBucketName 是相同的,即 spark-bucket
.
现在还有另外两个参数,即 blobName 和 destBlobName。
在你的情况下 blobName 应该是 directoryA/subdirectoryA/textfile.txt
而 destBlobName 应该是 directoryA/subdirectoryB/textfile.txt
.
所以简而言之 -
sourceBucketName = “spark-bucket”
destBucketName = “spark-bucket”
blobName = “directoryA/subdirectoryA/textfile.txt”
destBlobName = “directoryA/subdirectoryB/textfile.txt”
我有一个 Spark 作业,我想在其中使用 google.cloud.storage.StorageOptions
将 Google Cloud Storage 存储桶中的文本文件从目录 A 移动到目录 B源文件路径 = "gs://spark-bucket/directoryA/subdirectoryA/textfile.txt"
dest bucket location = "gs://spark-bucket/directoryA/subdirectoryB/"
sourceBucketName、blobName 和 destBucketName 应该是什么?是否必须是完整路径“gs://spark-bucket/directoryA/subdirectoryA/”或只是存储桶名称,即基于上述源文件路径的“spark-bucket”?
val storage = StorageOptions.newBuilder.setProjectId("project-id").build.getService
val blobId = BlobId.of(sourceBucketName, blobName)
val blob = storage.get(blobId)
val copyWriter = blob.copyTo(destBucketName, destBlobName)
blob.delete();
您想将 textfile.txt
从 gs://spark-bucket/directoryA/subdirectoryA/
移动到 gs://spark-bucket/directoryA/subdirectoryB/
从你的问题可以看出你只有一个桶,即 spark-bucket。所以 sourceBucketName 和 destBucketName 是相同的,即 spark-bucket
.
现在还有另外两个参数,即 blobName 和 destBlobName。
在你的情况下 blobName 应该是 directoryA/subdirectoryA/textfile.txt
而 destBlobName 应该是 directoryA/subdirectoryB/textfile.txt
.
所以简而言之 -
sourceBucketName = “spark-bucket”
destBucketName = “spark-bucket”
blobName = “directoryA/subdirectoryA/textfile.txt”
destBlobName = “directoryA/subdirectoryB/textfile.txt”