为啥我收到错误此驱动程序不支持使用 cloudinary-laravel 检索 URL?
Posted
技术标签:
【中文标题】为啥我收到错误此驱动程序不支持使用 cloudinary-laravel 检索 URL?【英文标题】:Why I got error This driver does not support retrieving URLs with cloudinary-laravel?为什么我收到错误此驱动程序不支持使用 cloudinary-laravel 检索 URL? 【发布时间】:2021-10-01 19:12:57 【问题描述】:在 laravel 8 应用程序中,我需要将图像从本地存储上传到 cloudinary(使用 cloudinary-laravel 1.0) 代码如下:
Storage::disk('cloudinary')->put('cl_filename.ext', Storage::disk('local')->get('local_filename.ext'));
但我得到了错误:
This driver does not support retrieving URLs.
在环境文件中:
CLOUDINARY_URL="cloudinary://XXXXXXXXXXX:XXXXXXXXXXXXX@cloudinaryname"
CLOUDINARY_UPLOAD_PRESET=ml_default
CLOUDINARY_NOTIFICATION_URL=
CLOUDINARY_ROOT_DIRECTORY=TAdsMedia
CLOUDINARY_API_KEY=XXXXXXXXXXX
CLOUDINARY_API_SECRET=XXXXXXXXXXXXX
CLOUDINARY_API_NAME=cloudinaryname
当我使用像 storeOnCloudinaryAs 这样的云计算方法时,它对我来说没问题,但不是存储方法。 在 config/filesystems.php 我添加了几行:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'cloudinary' => [// NOT SURE ARE THESE PARAMS VALID ?
'driver' => 'cloudinary',
'api_key' => env('CLOUDINARY_API_KEY'),
'api_secret' => env('CLOUDINARY_API_SECRET'),
'cloud_name' => env('CLOUDINARY_API_NAME'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
],
],
但是清除缓存我还是有同样的错误......
我的配置有问题吗?如何解决?
composer.json :
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require":
"php": "^7.3|^8.0",
"arcanedev/log-viewer": "^8.1",
"arcanedev/no-captcha": "^12.2",
"cloudinary-labs/cloudinary-laravel": "^1.0",
"cviebrock/eloquent-sluggable": "^8.0",
"diglactic/laravel-breadcrumbs": "^6.1",
"drewm/mailchimp-api": "^2.5",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"jenssegers/agent": "^2.6",
"laravel/fortify": "^1.7",
"laravel/framework": "^8.12",
"laravel/sanctum": "^2.8",
"laravel/socialite": "^5.2",
"laravel/tinker": "^2.5",
"laravelcollective/html": "^6.2",
"league/flysystem-aws-s3-v3": "^1.0",
"league/geotools": "@stable",
"maatwebsite/excel": "^3.1",
"mailchimp/mailchimp": "^2.0",
"menarasolutions/geographer": "^0.3.10",
"mews/purifier": "^3.3",
"mobiledetect/mobiledetectlib": "^2.8",
"monarobase/country-list": "^3.2",
"pragmarx/countries": "^0.7.2",
"spatie/browsershot": "^3.40",
"spatie/emoji": "^2.2",
"spatie/geocoder": "^3.10",
"spatie/laravel-permission": "^4.0",
"stidges/laravel-country-flags": "^2.0",
"stripe/stripe-php": "^7.75",
"toin0u/geocoder-laravel": "^4.4",
"wboyz/laravel-enum": "^0.2.1",
"webpatser/laravel-uuid": "^3.0"
,
"require-dev":
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel-frontend-presets/tailwindcss": "^4.3",
"laravel/sail": "^1.0.1",
"laravel/telescope": "^4.4",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
,
"config":
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
,
"extra":
"laravel":
"dont-discover": [
"laravel/telescope"
]
,
"autoload":
"files": [
"app/Library/helper.php"
],
"psr-4":
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
,
"autoload-dev":
"psr-4":
"Tests\\": "tests/"
,
"minimum-stability": "dev",
"prefer-stable": true,
"scripts":
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
如何解决这个错误?
修改 1: 我想 首先我需要安装 carlosocarvalho/flysystem-cloudinary 和下一个 xiaomlove/laravel-filesystem-cloudinary,但安装时出错:
Problem 1
- Conclusion: don't install carlosocarvalho/flysystem-cloudinary v2.0.2
- Conclusion: don't install laravel-frontend-presets/tailwindcss 4.3.1
- Conclusion: don't install league/flysystem 1.1.4
- Conclusion: don't install carlosocarvalho/flysystem-cloudinary v2.0.1
- Conclusion: don't install league/flysystem 1.1.3
- Installation request for laravel-frontend-presets/tailwindcss ^4.3 -> satisfiable by laravel-frontend-presets/tailwindcss[4.3.0, 4.3.1].
- Installation request for laravel/framework ^8.51.0 -> satisfiable by laravel/framework[8.x-dev, v8.51.0].
- Conclusion: don't install carlosocarvalho/flysystem-cloudinary v2.0.0
- laravel-frontend-presets/tailwindcss 4.3.0 requires laravel/framework ^8.0 -> satisfiable by laravel/framework[8.x-dev, v8.51.0].
- laravel/framework v8.51.0 requires league/flysystem ^1.1 -> satisfiable by league/flysystem[1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.x-dev].
- laravel/framework 8.x-dev requires league/flysystem ^1.1 -> satisfiable by league/flysystem[1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.x-dev].
- Can only install one of: league/flysystem[2.x-dev, 1.1.0].
- Can only install one of: league/flysystem[2.x-dev, 1.1.1].
- Can only install one of: league/flysystem[2.x-dev, 1.1.2].
- Can only install one of: league/flysystem[2.x-dev, 1.x-dev].
- carlosocarvalho/flysystem-cloudinary 2.0.0-alpha requires league/flysystem 2.x-dev -> satisfiable by league/flysystem[2.x-dev].
- Installation request for carlosocarvalho/flysystem-cloudinary ^2.0 -> satisfiable by carlosocarvalho/flysystem-cloudinary[2.0.0-alpha, v2.0.0, v2.0.1, v2.0.2].
我尝试先安装 League\Flysystem :
但是失败了。请提供任何提示
composer require league/flysystem :^2.2.0
...
Problem 1
- Installation request for league/flysystem ^2.2.0 -> satisfiable by league/flysystem[2.2.0, 2.x-dev].
- Installation request for laravel-frontend-presets/tailwindcss ^4.3.1 -> satisfiable by laravel-frontend-presets/tailwindcss[4.3.1].
- laravel-frontend-presets/tailwindcss 4.3.1 requires laravel/framework ^8.0 -> satisfiable by laravel/framework[8.x-dev, v8.51.0].
- laravel/framework 8.x-dev requires league/flysystem ^1.1 -> satisfiable by league/flysystem[1.x-dev].
- laravel/framework v8.51.0 requires league/flysystem ^1.1 -> satisfiable by league/flysystem[1.x-dev].
- Conclusion: don't install league/flysystem 1.x-dev
我尝试修改 composer.json 来修复这些错误,例如:
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require":
"php": "^7.3|^8.0",
"arcanedev/log-viewer": "^8.1",
"arcanedev/no-captcha": "^12.2",
"cloudinary-labs/cloudinary-laravel": "^1.0",
"cviebrock/eloquent-sluggable": "^8.0",
"diglactic/laravel-breadcrumbs": "^6.1",
"drewm/mailchimp-api": "^2.5",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.1.1",
"jenssegers/agent": "^2.6",
"laravel/fortify": "^1.7",
"laravel/framework": "^8.51.0",
"laravel/sanctum": "^2.8",
"laravel/socialite": "^5.2",
"laravel/tinker": "^2.5",
"laravelcollective/html": "^6.2",
"league/geotools": "@stable",
"maatwebsite/excel": "^3.1",
"mailchimp/mailchimp": "^2.0",
"menarasolutions/geographer": "^0.3.10",
"mews/purifier": "^3.3",
"mobiledetect/mobiledetectlib": "^2.8",
"monarobase/country-list": "^3.2",
"pragmarx/countries": "^0.7.2",
"spatie/browsershot": "^3.40",
"spatie/emoji": "^2.2",
"spatie/geocoder": "^3.10",
"spatie/laravel-permission": "^4.0",
"stidges/laravel-country-flags": "^2.0",
"stripe/stripe-php": "^7.75",
"toin0u/geocoder-laravel": "^4.4",
"wboyz/laravel-enum": "^0.2.1",
"webpatser/laravel-uuid": "^3.0"
,
"require-dev":
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel-frontend-presets/tailwindcss": "^4.3.1",
"laravel/sail": "^1.0.1",
"laravel/telescope": "^4.4",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
,
"config":
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
,
"extra":
"laravel":
"dont-discover": [
"laravel/telescope"
]
,
"autoload":
"files": [
"app/Library/helper.php"
],
"psr-4":
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
,
"autoload-dev":
"psr-4":
"Tests\\": "tests/"
,
"minimum-stability": "dev",
"prefer-stable": true,
"scripts":
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
任何提示如何解决?
修改 2: 由于我未能安装 laravel-filesystem-cloudinary 我仍然尝试使用如下代码:
Storage::disk('cloudinary')->put('cl_filename.ext', Storage::disk('local')->get('local_filename.ext'));
但是当我遇到错误时 此驱动程序不支持检索 URL。
我尝试在文件中调试源代码并打开文件 vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:
和调试url方法,比如:
public function url($path)
\Log::info( varDump($path, ' -1 url $path::') );
$adapter = $this->driver->getAdapter();
\Log::info( varDump($adapter, ' -1 url $adapter::') );
if ($adapter instanceof CachedAdapter)
$adapter = $adapter->getAdapter();
\Log::info( varDump($adapter, ' -2 INSIDE url $adapter::') );
if (method_exists($adapter, 'getUrl'))
return $adapter->getUrl($path);
elseif (method_exists($this->driver, 'getUrl'))
return $this->driver->getUrl($path);
elseif ($adapter instanceof AwsS3Adapter)
return $this->getAwsUrl($adapter, $path);
elseif ($adapter instanceof Ftp || $adapter instanceof Sftp)
return $this->getFtpUrl($path);
elseif ($adapter instanceof LocalAdapter)
return $this->getLocalUrl($path);
else
throw new RuntimeException('This driver does not support retrieving URLs.');
我看到了输出
[2021-07-28 09:18:01] local.INFO: NULL : -1 url $path:: : NULL
[2021-07-28 09:18:01] local.INFO: (Object of CloudinaryLabs\CloudinaryLaravel\CloudinaryAdapter) : -1 url $adapter:: : Array
(
[cloudinary] => Cloudinary\Cloudinary Object
(
[configuration] => Cloudinary\Configuration\Configuration Object
(
[sections:protected] => Array
(
[0] => cloud
[1] => api
[2] => url
[3] => tag
[4] => responsive_breakpoints
[5] => auth_token
[6] => logging
)
[includeSensitive:protected] => 1
[cloud] => Cloudinary\Configuration\CloudConfig Object
(
[cloudName] => NNNNNNNNNNN
[apiKey] => XXXXXXXXXXXXXXXXXXX
[apiSecret] => WWWWWWWWWWWW
[oauthToken] =>
[explicitlySetKeys:protected] => Array
(
[cloudName] => 1
[apiKey] => 1
[apiSecret] => 1
)
)
[api] => Cloudinary\Configuration\ApiConfig Object
(
[uploadPrefix:protected] =>
[apiProxy] =>
[connectionTimeout] =>
[timeout:protected] =>
[uploadTimeout:protected] =>
[chunkSize:protected] =>
[callbackUrl] =>
[explicitlySetKeys:protected] => Array
(
)
)
至于 Cloudinary Adapter 方法 url 未找到,我无法手动编辑“vendor/”下的文件 它必须以其他方式完成吗?
谢谢!
【问题讨论】:
请看 MODIFIED 2 【参考方案1】:您需要一个自定义文件系统,请参阅:https://laravel.com/docs/8.x/filesystem#custom-filesystems
您可以自己创建它或使用现有的包,例如在谷歌搜索后我发现了这个。 https://github.com/xiaomlove/laravel-filesystem-cloudinary
【讨论】:
请看 MODIFIED 1以上是关于为啥我收到错误此驱动程序不支持使用 cloudinary-laravel 检索 URL?的主要内容,如果未能解决你的问题,请参考以下文章