Dipendra Gurung
Dipendra Gurung

Reputation: 5870

Laravel Filesystem: Managing Folders in Google Drive API

I am following this tutorial:- https://gist.github.com/sergomet/f234cc7a8351352170eb547cccd65011

My Laravel application requires files to be organized inside a folder. So, whenever a file is uploaded it should be saved inside a folder that it belongs to.

Before uploading a file, I must check whether the folder exists or not. In Laravel, I have used this method to list all the directories at root.

$directories = Storage::directories();

However, it returns a list of alphanumeric unique ids with no references to the human readable names. I don't want to create duplicate folder even though it is possible in Google drive.

So, how do we get list of folder names along with reference id?

Upvotes: 1

Views: 2681

Answers (1)

Ben
Ben

Reputation: 5129

The proper way you should create a lookup table and store the id and folder names. Otherwise if you are querying the folder name you will need to fetch the meta data by id:

$metadata = Storage::disk('gdrive')->getAdapter()->getMetadata($folderId);

The metadata format can be check here. You may notice that Google Drive is ID based filesystem, so this connector need ID based path.

Upvotes: 3

Related Questions