flysystem-google-drive icon indicating copy to clipboard operation
flysystem-google-drive copied to clipboard

How to create sub directory

Open JILeXanDR opened this issue 7 years ago • 11 comments

use Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter;
use League\Flysystem\Filesystem;

$client = new Google_Client();

$client->setAuthConfigFile('path_to_json_file');
$client->setScopes(['https://www.googleapis.com/auth/drive']);

$googleDriveFileManager = new Filesystem(
    new GoogleDriveAdapter(
        new Google_Service_Drive($client),
        'root'
    )
);

$result = $googleDriveFileManager->createDir('_test');
echo $result;exit; // displays 1

Result is 1, but there is no created directory on my Google Drive. What is the reason in?

JILeXanDR avatar Mar 14 '17 13:03 JILeXanDR

@JILeXanDR Please check result with var_dump($result); instead to echo $result;.

nao-pon avatar Mar 14 '17 14:03 nao-pon

@nao-pon It returns bool(true)

JILeXanDR avatar Mar 14 '17 16:03 JILeXanDR

Umm... I'm not sure. What is result $googleDriveFileManager->listContents('root');?

nao-pon avatar Mar 15 '17 02:03 nao-pon

@nao-pon

var_dump(implode(', ', array_pluck($cloud->listContents('root'), 'filename')));exit;

There are a lot of created directories by me. But they are not visible in Google Drive

_test, _test, _test, _test, _test, _test, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, _test, _test, _test, GOOGLE_DRIVE_SYNC, root, GOOGLE_DRIVE_SYNC, GOOGLE_DRIVE_SYNC, _test, _test, Getting started, _test, root, 1111, _test, _test, _test, GOOGLE_DRIVE_SYNC, _test, GOOGLE_DRIVE_SYNC, _test, _test, _test, _test, xxx, _test, _test, GOOGLE_DRIVE_SYNC, _test, _test, _test, GOOGLE_DRIVE_SYNC, test, _test, test, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, 1111, _test, test, _test, _test, GOOGLE_DRIVE_SYNC, test, _test, _test, _test, _test, GOOGLE_DRIVE_SYNC, _test, 1111, root, _test, _test, _test, _test, _test, _test, _test, _test, _test, _test, GOOGLE_DRIVE_SYNC, _test, _test, _test, _test, GOOGLE_DRIVE_SYNC, GOOGLE_DRIVE_SYNC, _test, test, GOOGLE_DRIVE_SYNC, 1111, _test, _test, _test

JILeXanDR avatar Mar 15 '17 07:03 JILeXanDR

For example when I try to create sub-directory (in already created by me but not visible in list)

$cloud->createDir('GOOGLE_DRIVE_SYNC/images');

action is finished with error

[Google_Service_Exception]                            
  {                                                     
   "error": {                                           
    "errors": [                                         
     {                                                  
      "domain": "global",                               
      "reason": "notFound",                             
      "message": "File not found: GOOGLE_DRIVE_SYNC.",  
      "locationType": "parameter",                      
      "location": "fileId"                              
     }                                                  
    ],                                                  
    "code": 404,                                        
    "message": "File not found: GOOGLE_DRIVE_SYNC."     
   }                                                    
  }

JILeXanDR avatar Mar 15 '17 07:03 JILeXanDR

Used version is 1.1

JILeXanDR avatar Mar 15 '17 07:03 JILeXanDR

Google Drive is ID based filesystem, so this connector need ID based path. e.g. $cloud->createDir('FOLDER ID/images');

nao-pon avatar Mar 16 '17 00:03 nao-pon

Problem with not existed directory was solved. Need use unique "path" instead of real name of directory.

array(8) {
    ["type"]=>
    string(3) "dir"
    ["path"]=>
    string(33) "root/0ByPeQhcJr3-DRDVzd3BFUGZtWU0"
    ["filename"]=>
    string(3) "zip"
    ["extension"]=>
    string(0) ""
    ["timestamp"]=>
    int(1489679824)
    ["size"]=>
    int(0)
    ["dirname"]=>
    string(4) "root"
    ["basename"]=>
    string(28) "0ByPeQhcJr3-DRDVzd3BFUGZtWU0"
  }

This code works

$cloud->createDir('root/0ByPeQhcJr3-DRDVzd3BFUGZtWU0/fileOrDirName');

@nao-pon But created files and directories are still not visible in Google Drive UI

JILeXanDR avatar Mar 17 '17 07:03 JILeXanDR

But created files and directories are still not visible in Google Drive UI

Please connect with the account you want to display on GoogleDrive UI by OAuth authentication.

c.f. Getting your Client ID and Client Secret

nao-pon avatar Mar 17 '17 12:03 nao-pon

@nao-pon I've used this way and got the following error:

[Google_Service_Exception]        
  {                                 
   "error": {                       
    "errors": [                     
     {                              
      "domain": "global",           
      "reason": "required",         
      "message": "Login Required",  
      "locationType": "header",     
      "location": "Authorization"   
     }                              
    ],                              
    "code": 401,                    
    "message": "Login Required"     
   }                                
  }

JILeXanDR avatar Mar 17 '17 19:03 JILeXanDR

Sam me

giangmd avatar Jun 05 '17 17:06 giangmd