Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Save zip file in storage s3 aws laravel 9

I’m asking for your help because I can’t figure out where the error is.
I’m creating a backup zip file of a folder in Laravel and I want to automatically save it on the Amazon S3 server. I’ve already set up the entire FyleSystem, ID keys etc.. the point is that now on the Amazon server it only saves the name of the file and not the archive .zip, can I ask for your help to understand why it doesn’t save the entire archive but only the name?

This is code

  $zip = new ZipArchive;

        $azienda = User::value('azienda');

        $fileName = time() . $azienda . ".zip";

        if ($zip->open(public_path($fileName), ZipArchive::CREATE) === TRUE) {

            $files = File::files(public_path('/images/images'));

            foreach ($files as $key => $value) {
                $relativeNameInZipFile = basename($value);
                $zip->addFile($value, $relativeNameInZipFile);

            }
            $zip->close();
        };

        Storage::disk('s3')->put('public/backup', $fileName);

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

thanks a lot to everyone

>Solution :

Storage::put takes either a string contents or a file resource. It does not take file names, and will treat it as the string it is.

https://laravel.com/docs/10.x/filesystem#storing-files

Storage::disk('s3')->put('public/backup', fopen($filename, 'r'));

or, for lower memory usage, stream it:

Storage::disk('s3')->putFile('public/backup', new \Illuminate\Http\File($filename));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading