nao-pon / flysystem-google-drive

Flysystem adapter for Google Drive
MIT License
352 stars 128 forks source link

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

Open swamyyadav opened 3 years ago

swamyyadav commented 3 years ago

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!';
        }
    }
PaolaRuby commented 3 years ago

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');
swamyyadav commented 3 years ago

Thank you, ill check.