spatie/laravel-personal-data-export

Corrupted (.pcgz) file is generated when opening the downloaded .zip file

hazem-taha opened this issue · 1 comments

Discussed in #61

Originally posted by hazem-taha June 24, 2021
Hello,

After clicking the downloaded .zip file, that file is generated as per the below screenshot..
image

this is the implemented methods in my model class..

    public function selectPersonalData(PersonalDataSelection $personalData): void
    {
        $personalData
            ->add('user.json', [
             'name' => $this->name,
            'email' => $this->email,
            ]);
    }

    public function personalDataExportName(): string {
        $userName = Str::slug($this->name);

        return "personal-data-{$userName}.zip";
    }

I'm using Laravel v8.20.1

my config/personal-data-export.php file..

<?php

return [
    /*
     * The disk where the exports will be stored by default.
     */
    'disk' => 'personal-data-exports',

    /*
     * The amount of days the exports will be available.
     */
    'delete_after_days' => 5,

    /*
     * Determines whether the user should be logged in to be able
     * to access the export.
     */
    'authentication_required' => false,

    /*
     * The mailable which will be sent to the user when the export
     * has been created.
     */
    'mailable' => \Spatie\PersonalDataExport\Mail\PersonalDataExportCreatedMail::class,

    /*
     * Configure the queue and connection used by `CreatePersonalDataExportJob`
     * which will create the export.
     */
    'job' => [
        'queue' => null,
        'connection' => null,
    ],
];

I found something weird, the files generated inside storage/app/personal-data-exports are valid and correct but when they are downloaded, they become corrupted

Thanks in advance.

OK I found the solution, I had to add ob_end_clean(); before starting streaming the file, but why do I need to use this to fix ?!