0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel S3にzipファイルを保存する

Posted at

LaravelでS3上のデータを使用して、S3にzipファイルを作成する方法を記載。

ライブラリをインストール


composer require stechstudio/laravel-zipstream


zip作成。

$zip_listには['file_path'=>'/xxx/xxx','original_file_name'=>'name']
の形で配列を入れておく。
file_path:S3のパス
original_file_name:pdfのファイルネーム

use Zip;
use Storage;

 public function createZip(array $zip_list,string $zip_file_name)
    {
        $zipFilePath = '/zipdir';
        $bucket_private = config('filesystems.disks.private_s3.bucket');

        $zip = Zip::create($zip_file_name);
        $lengs = count($zip_list);
        for( $i = 0; $i < $lengs; $i ++ ){
            $file_path = $zip_list[$i]['file_path'];
            $original_file_name = $zip_list[$i]['original_file_name'];
            
            $contents = Storage::disk(config('filesystems.private_s3'))->get($file_path);
            $zip->addRaw($contents, $original_file_name);
        }
        $save_url = 's3://'.$bucket_private.$zipFilePath;
        $zip->saveTo($save_url);
    }

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?