spatie / flysystem-dropbox

A flysystem driver for Dropbox that uses the v2 API
https://freek.dev/734-dropbox-will-turn-off-v1-of-their-api-soon-its-time-to-update-your-php-application
MIT License
343 stars 50 forks source link

Empty array when show files within a path #47

Closed YeeJiaWei closed 4 years ago

YeeJiaWei commented 5 years ago

I can display the dropbox folder and files using this spatie/dropbox-api

$client = new \Spatie\Dropbox\Client($authorizationToken);
$folder = $client->listFolder('path');

However, using this will ouput me an array without anything

// In laravel

$storage = Storage::disk('dropbox')->files('path');
connor-simpson commented 5 years ago

If you have implemented spatie/flysystem-dropbox through a Laravel service provider and followed the documentation on the Laravel website then it likely you've missed something that's actually pretty important.

Note: Because Dropbox is not case-sensitive you’ll need to set the 'case_sensitive' option to false.

In the server provider you created for Laravel replace the following:

return new Filesystem(new DropboxAdapter($client));

to

return new Filesystem(new DropboxAdapter($client), ['case_sensitive' => false]);
spatie-bot commented 4 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

Doomkyn commented 4 years ago

I'm sorry for resuming this, but I have the same problem, also setup the case_sensitive option, but no luck. Any tip?

Doomkyn commented 4 years ago

The problem is definitely with case sensitivity. I checked the full flow of dropbox api, and I found out that this function inside Client.php

    public function listFolder(string $path = '', bool $recursive = false): array
    {
        $parameters = [
            'path' => $this->normalizePath($path),
            'recursive' => $recursive,
        ];
        return $this->rpcEndpointRequest('files/list_folder', $parameters);
    }

returns the path with wrong case. Even setting the case_sensitive option to false doesn't solve the problem.

In my case, my path is full uppercase, so I tried editing this line $normalizedPath = ltrim($this->removePathPrefix($response['path_display']), '/'); to $normalizedPath = ltrim($this->removePathPrefix(strtoupper($response['path_display'])), '/'); inside the normalizeResponse function of DropboxAdapter.php and now it returns the right subfolders. However, this cannot be the fix because it will not work if I have a non-full uppercase folder.

Hope we can find a fix for this.

eusonlito commented 4 years ago

@Doomkyn is not a library problem, is a Dropbox API problem: https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/2-files-list-folder-not-consistent-with-results-in-path-display/m-p/208355/highlight/true#M10238

Unfortunately due to some specifics of how Dropbox is implemented, not all of the path components can be guaranteed to have the expected casing.

Dropbox API is not consistent on case paths on some API endpoints.

If you are using some \League\Flysystem\Cached\CachedAdapter, they are not also case insensitive: https://github.com/thephpleague/flysystem-cached-adapter/issues/36