user01380121
user01380121

Reputation: 527

Move Cloud Storage file to different bucket with Java API

How can I move a file from one bucket to another with the Cloud Storage Java API? I can find examples of file creation but not copying or deletion - and I imagine I'd have to copy the file and delete it in order to execute a move from one bucket to another.

Upvotes: 0

Views: 1988

Answers (1)

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38399

You're correct. Do the copy and then delete the original after. There are some examples on GitHub. Here's the gist of it:

 CopyWriter copyWriter = originalBlob.copyTo(BlobId.of(bucketName, blobName));
 Blob copiedBlob = copyWriter.getResult();

Upvotes: 1

Related Questions