sam_ten2001
sam_ten2001

Reputation: 33

How to upload files to specific folder on cloud storage via api

My application running on computer engine creates images which I upload to cloud storage. This works well using

BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          filePart.getInputStream());

But I need to upload this to specific folder like 'bucketname/170717/'

Couldn't find way to upload to specific folder. Any pointers would be appreciated.

Upvotes: 0

Views: 1095

Answers (1)

sam_ten2001
sam_ten2001

Reputation: 33

So finally I got the solution.

storage.create( BlobInfo .newBuilder(bucketName, fileName)

In above snippet of code if fileName has a folder path, cloud storage creates it. So when I passed "images/" + fileName a new folder images was created and file was created inside that.

Upvotes: 2

Related Questions