@@ -157,6 +157,27 @@ void RenameObject(google::cloud::storage::Client client,
157157 (std::move (client), argv.at (0 ), argv.at (1 ), argv.at (2 ));
158158}
159159
160+ void MoveObject (google::cloud::storage::Client client,
161+ std::vector<std::string> const & argv) {
162+ // [START storage_move_object]
163+ namespace gcs = ::google::cloud::storage;
164+ using ::google::cloud::StatusOr;
165+ [](gcs::Client client, std::string const & bucket_name,
166+ std::string const & source_object_name,
167+ std::string const & destination_object_name) {
168+ StatusOr<gcs::ObjectMetadata> metadata = client.MoveObject (
169+ bucket_name, source_object_name, destination_object_name);
170+ if (!metadata) throw std::move (metadata).status ();
171+
172+ std::cout << " Successfully renamed " << source_object_name << " to "
173+ << destination_object_name << " in bucket " << bucket_name
174+ << " .\n " ;
175+ }
176+
177+ // [END storage_move_object]
178+ (std::move (client), argv.at (0 ), argv.at (1 ), argv.at (2 ));
179+ }
180+
160181void RunAll (std::vector<std::string> const & argv) {
161182 namespace examples = ::google::cloud::storage::examples;
162183 namespace gcs = ::google::cloud::storage;
@@ -251,6 +272,16 @@ void RunAll(std::vector<std::string> const& argv) {
251272
252273 (void )client.DeleteObject (destination_bucket_name, dst_object_name);
253274 (void )client.DeleteObject (bucket_name, src_object_name);
275+
276+ std::cout << " \n Creating an object to run the MoveObject() example"
277+ << std::endl;
278+ (void )client.InsertObject (bucket_name, src_object_name, kText ).value ();
279+
280+ std::cout << " \n Running the MoveObject() example" << std::endl;
281+ MoveObject (client, {bucket_name, src_object_name, dst_object_name});
282+
283+ std::cout << " \n Cleanup" << std::endl;
284+ (void )client.DeleteObject (bucket_name, dst_object_name);
254285}
255286
256287} // namespace
@@ -275,6 +306,10 @@ int main(int argc, char* argv[]) {
275306 " rename-object" ,
276307 {" <bucket-name>" , " <old-object-name>" , " <new-object-name>" },
277308 RenameObject),
309+ examples::CreateCommandEntry (" move-object" ,
310+ {" <bucket-name>" , " <source-object-name>" ,
311+ " <destination-object-name>" },
312+ MoveObject),
278313 {" auto" , RunAll},
279314 });
280315 return example.Run (argc, argv);
0 commit comments