nao-pon / flysystem-google-drive

Flysystem adapter for Google Drive
MIT License
349 stars 127 forks source link

How to create sub directory #11

Open JILeXanDR opened 7 years ago

JILeXanDR commented 7 years ago
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?

nao-pon commented 7 years ago

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

JILeXanDR commented 7 years ago

@nao-pon It returns bool(true)

nao-pon commented 7 years ago

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

JILeXanDR commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

Used version is 1.1

nao-pon commented 7 years ago

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

JILeXanDR commented 7 years ago

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

nao-pon commented 7 years ago

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

JILeXanDR commented 7 years ago

@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"     
   }                                
  }
giangmd commented 7 years ago

Sam me