【问题标题】:No such file, Storing file into the local storage is not working on production没有这样的文件,将文件存储到本地存储中不适用于生产
【发布时间】:2020-06-01 11:44:18
【问题描述】:

我在 Elasticbeanstalk 上部署了一个 laravel 应用程序,我正在开发一个功能,我需要从 s3 存储桶中获取一个 zip 文件,将其存储到本地存储中,以便能够使用 laravel-zip 删除一个来自该 zip 的 pdf 文件。 该代码在本地运行,但在生产测试后我收到“没有此类文件错误”:

// get the file from s3 and store it into local storage
$contents  = Storage::disk('s3')->get($file_name);
$zip_local_name =  'my_file.zip';
Storage::disk('local')->put($zip_local_name, $contents);

// use laravel-zip to remove the unwanted pdf file from the result
$manager = new ZipManager();
$file_path = storage_path('app').'\\'.$zip_local_name; // register existing zips
$manager->addZip(Zip::open($file_path));
$zip = $manager->getZip(0);
$zip->delete($data["Iso_Bus"]["field_name"].'.pdf');
$zip->close();

我确保该文件存在于 s3 上,所以我认为我的主要问题是该文件未存储在本地存储中。 任何帮助表示赞赏

编辑文件系统配置:

'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' => '***',
            'secret' => '***',
            'region' => '***',
            'bucket' => '****',
            'url' => '****',
        ],

    ],

【问题讨论】:

  • 你确定你有写权限,你能添加你的 filesystems.php 配置吗?
  • 请给我一个mnt
  • @JasperHelmich 你能解释一下我需要什么写权限吗?
  • @FurqanS.Mahmoud 您在哪一行收到此错误?
  • @HA $manager->addZip(Zip::open($file_path));

标签: laravel amazon-elastic-beanstalk


【解决方案1】:

您错误地获取了文件的完整路径,请尝试以下方法:

$file_path = Storage::disk('local')->path($zip_local_name);

注意:最好在继续之前检查Storage::put是否成功:

// get the file from s3 and store it into local storage
$contents  = Storage::disk('s3')->get($file_name);
$zip_local_name =  'my_file.zip';

if (Storage::disk('local')->put($zip_local_name, $contents)) {
    // `Storage::put` returns `true` on success, `false` on failure.
    // use laravel-zip to remove the unwanted pdf file from the result
    $manager = new ZipManager();
    $file_path = $file_path = Storage::disk('local')->path($zip_local_name);
    $manager->addZip(Zip::open($file_path));
    $zip = $manager->getZip(0);
    $zip->delete($data["Iso_Bus"]["field_name"].'.pdf');
    $zip->close();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    • 2017-10-21
    • 2012-10-31
    • 2012-03-31
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多