soarecostin / file-vault

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

Sometimes fils don't download from S3 #21

Closed flywolfcreative closed 2 years ago

flywolfcreative commented 2 years ago

I have implemented a system with keys and hooked up to S3. Most of the time it works like a dream, files will upload, encrypt and then my queue sends it to S3. Downloading uses stream decrypt, just as the docs mention.

Occasionally though, I'll have a file which when i download through streamDecrypt will just do nothing. I can't get any kind of error message out of it either. If I upload the exact same file and try downloading that, it will work. But that original one doesn't.

Looking in S3, it did successfully upload, the file size is correct on each upload of the same file, but some download and others dont. It has me really stumped.

How might i get some kind of debug info out of the streamDecrypt so I can find out why some files it just doesn't like?

Here's my download script:

$path = $file->file_url.$file->file_name.'.enc';
if (Storage::disk('s3')->has($path)) {
return response()->streamDownload(function () use($path, $encryptionKey) {

    if($encryptionKey){ // it will use the default encryption key if doc-library
        FileVault::disk('s3')->key($encryptionKey)->streamDecrypt($path);
    }else{
        FileVault::disk('s3')->streamDecrypt($path);
    }

}, $file->file_name, array(
    'Content-Type' => str_replace('-', '/', $file->mime) // mime stored in db as example: 'image-jpeg'
));

}else{
echo 'File not found';
}

Thanks

flywolfcreative commented 2 years ago

Ok I think my issue is actually at the upload stage, I'm using resumable.js and I think sometimes it misses chunks, which then makes the download fail.

However, I would like to know how to better debug the FileVault::disk('s3')->streamDecrypt($path) if anyone knows?

flywolfcreative commented 2 years ago

20 I believe this fork addresses the issue i have been having with Decryption Errors.