nao-pon/flysystem-google-drive

How do i search the file by using file name in the google drive by using this plugin

swamyyadav opened this issue · 2 comments

Currently, I'm getting the list files from the folder, I know this will take more time to execute if the folder contains more no.of files.
below is the code snippet, please help me with a solution.

public static function getFileLink($folder_name,$file_name){
        $google_folders = Session::get('google_folders');
        $floder_name = $folder_name;
        $folder_id = $google_folders[$floder_name];
        $files = Storage::disk('google')->allFiles($folder_id);
        $db_file_name = $file_name;
        if(count($files)>0){
            foreach ($files as $file) {
                $firstName = $file;
                $details = Storage::disk('google')->getMetadata($firstName);
            if($details['name']== $db_file_name){
                  return $url = Storage::disk('google')->url($firstName);
            }
          }
        }else{
            return 'No File Found!';
        }
    }

First always use [<>] button for code, second this package doesn' have support, i'm using masbug/flysystem-google-drive-ext wich has the same config but works with paths, only you has to do

Storage::disk('google')->getDriver()->getAdapter()->getMetadata('path/to/your/file.txt');

Thank you, ill check.