php - Laravel php artisan 配置 :cache and AWS S3 access error

标签 php laravel amazon-web-services laravel-5 amazon-s3

我面临一个非常奇怪的情况,我期待您的帮助。

我与 Laravel 建立了 S3 连接。另一项服务是为我将视频文件上传到我的亚马逊存储桶。这些文件是用户通过我的网站下载的。

但是,该系统不会很快运行。文件已上传到存储桶,但用户无法访问此文件。

找了半天问题的根源,也没找到。后来,当我在我的伪造服务器上说“php artisan config: clear”时,系统又开始工作了。然后我想通过说“php artisan config:cache”来优化系统。但一切又回到了原来的状态。所以它开始不起作用。

我使用league/flysystem-aws-s3-v3包作为一个包。我正在尝试解决问题,请帮忙?

这是我的config/filesystem.php

return [

/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk, as well as a variety of cloud
| based disks are available to your application. Just store away!
|
*/

'default' => env('FILESYSTEM_DRIVER', 'local'),

/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem Disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason, you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/

'cloud' => env('FILESYSTEM_CLOUD', 's3'),

/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace"
|
*/

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    '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'),
    ],

],

];

这是我的 .env 文件。

AWS_ACCESS_KEY_ID="****"
AWS_SECRET_ACCESS_KEY="****"
AWS_DEFAULT_REGION="eu-west-3"
AWS_BUCKET="tokbox****"

然后我用这些行在我的 Controller 中检查并下载了文件;

$tokboxapikey = env('OPENTOK_API_KEY');

$exist = Storage::disk('s3')->exists($tokboxapikey . '/'. $archive_id.'/archive.mp4');
    if($exist)
    {
        return Storage::disk('s3')->download($tokboxapikey. '/'. $archive_id.'/archive.mp4');
    }

最佳答案

改变

$tokboxapikey = env('OPENTOK_API_KEY');

$tokboxapikey = config('tokbox.api_key');

现在 laravel 会在 bootstrap/cache/config.php 中查找 $tokboxapikey。

关于php - Laravel php artisan 配置 :cache and AWS S3 access error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51422312/

相关文章:

php - 我在这个 SQL 查询中做错了什么

php - 保留新行,当 HTML 位于 1 行并且使用 <div> 完成新行布局时

php - 'where' 中的 Laravel 数字比较不起作用

php - Laravel 路由到 Controller 操作

amazon-web-services - 如何在 Amazon Redshift 上执行预定的 SQL 脚本?

php - (PDO) 从 id 收集特定数据

PHP 在 soap 调用中重复元素

php - 使用未知数量的参数创建 Laravel Eloquent Query

amazon-web-services - AWS 上 Dockerfile 中的一些 GPG 命令突然失败

amazon-web-services - ejabberd 与 Riak 的集成