java - Unable to copy folders using Google Cloud Storage JSON API -


i have gae application created using java. have bucket folders , files i'm trying copy on bucket within same project. folder structure of bucket follows:

bucket_test     |-------folder1/                 |-----testtxt1.txt     |-------folder2/                 |-----testtxt2.txt 

i trying copy objects on using following code

string old_bucket = "bucket_test"; string new_bucket = "bucket_test_new";  bucket isbkt = new googlestoragehelper() .trycreatebucket(new_bucket, storage); storage.objects.list listobjects = storage.objects().list(old_bucket);  objects objects; objects = listobjects.execute();   (storageobject object : objects.getitems()) { storage.objects.copy copyobject  =  storage.objects() .copy(old_bucket, object.getname(), new_bucket, object.getname(), object);  try { system.out.println("trying copy on " + object.getname() + " " + old_bucket + " >>>> " + new_bucket); //copy file on new bucket object copyres = copyobject.execute(); system.out.println(copyres.tostring()); } catch (exception e) { system.out.println("exception trying copy on " + object.getname() + " " + e.getlocalizedmessage());     } 

what happening? following error:

{ "code" : 400, "errors" : [ { "domain" : "global", "message" : "invalid bucket name: 'bucket_test/folder1'.", "reason" : "invalidparameter", "extendedhelp" : "https://developers.google.com/storage/docs/bucketnaming"  } ],  "message" : "invalid bucket name: 'bucket_test/folder1'."   } } 

what should happen instead?

i expect copy files , folders on because both considered objects. able copy files on if directly in bucket , not inside folders.

  1. is there way copy files , folders over?
  2. do need list them using prefix , delimiters src: https://cloud.google.com/storage/docs/json_api/v1/objects/list?

in cloud storage, folders not considered objects. as stated in documentation :

because google cloud storage system has no notion of folders, folders created in google developers console convenience organize objects in bucket.

so happens if object name follows pattern "part1/part2/part3" browser show 2 folders "part1" , "part2" , file called "part". what's stored in system file called "part1/part2/part3".

as result, copying folder not mean cloud storage since folders don't exist. want copying files within folder "folder1". in case need :

  • list objects name start "folder1/"
  • for each of objects, issue copy command

you can use gsutil automates you.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -