Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an empty folder in google cloud bucket using Java API

I am using the JSON API - Google API Client Library for Java to access the objects in Google Cloud Storage. I need to create (not upload) an empty folder in the bucket. Google Developer Web Console has that option to creating a directory, but neither the Java API nor the gsutil command has a create folder command. If anybody knows how to do so, please let me know. Thanks in advance...

like image 800
Sakthi Ganesh Avatar asked Nov 13 '15 10:11

Sakthi Ganesh


2 Answers

You can emulate a folder by uploading a zero-sized object with a trailing slash.

As noted in the question comments, Google Cloud Storage is not a filesystem and emulating folders has serious limitations.

like image 145
Travis Hobrla Avatar answered Sep 28 '22 06:09

Travis Hobrla


I think is better that you create the folder within the file name. For example if you need a folder called images and other one called docs, when you give the name of the object to upload do it in the following way images/name_of_file or docs/name_of_file.

If the name of the file is images/dogImage and you upload that file, you will find in your bucket a folder called images.

I hope to help you and others

like image 40
user3326197 Avatar answered Sep 28 '22 04:09

user3326197