soarecostin / file-vault

A Laravel package for encrypting and decrypting files of any size
MIT License
185 stars 62 forks source link

streamDecrypt not working for custom disk using "S3" driver #26

Open muarachmann opened 1 year ago

muarachmann commented 1 year ago

Using the code doesn't download the file.

       return
            response()->streamDownload(function () use ($decFilename) {
                FileVault::disk('s3')->streamDecrypt($decFilename);
            }, Str::replaceLast('.enc', '', basename($decFilename)));

I keep getting the error Failed to open stream: No such file or directory meanwhile the upload to bucket works and the file is actually there in the bucket. Using Local bucket, it works fine but doesn't work with the s3 driver.

muarachmann commented 1 year ago

Update on this @soarecostin I noticed it was because I am using a custom disk configuration. e.g

'test-disk' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            'endpoint' => env('AWS_ENDPOINT'),
        ],

The streamDecrypt doesn't work as it fails to check if the disk is actually using the s3 driver here https://github.com/soarecostin/file-vault/blob/ee40ef4a3a7a23e64599a00f9ae5ff1c3b3597b5/src/FileVault.php#L175

here this->disk returns test-disk and thus fails with file not found.