没有此类文件,无法将文件存储到本地存储中

问题描述 投票:0回答:1

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

// 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上存在,所以我认为我的主要问题是文件未存储在本地存储中。任何帮助表示赞赏

Edit文件系统配置:

'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' => '****',
        ],

    ],
laravel amazon-elastic-beanstalk
1个回答
0
投票

您错误地获得了文件的完整路径,请尝试使用此路径:

$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();
}
© www.soinside.com 2019 - 2024. All rights reserved.