mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 12:24:50 +00:00
Fix for #1737
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Helpers\Attachments;
|
namespace FireflyIII\Helpers\Attachments;
|
||||||
|
|
||||||
use Crypt;
|
use Crypt;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Attachment;
|
use FireflyIII\Models\Attachment;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@@ -245,6 +246,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
*
|
*
|
||||||
* @return Attachment|null
|
* @return Attachment|null
|
||||||
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
protected function processFile(UploadedFile $file, Model $model): ?Attachment
|
protected function processFile(UploadedFile $file, Model $model): ?Attachment
|
||||||
{
|
{
|
||||||
@@ -266,6 +268,11 @@ class AttachmentHelper implements AttachmentHelperInterface
|
|||||||
|
|
||||||
$fileObject = $file->openFile('r');
|
$fileObject = $file->openFile('r');
|
||||||
$fileObject->rewind();
|
$fileObject->rewind();
|
||||||
|
|
||||||
|
if(0 === $file->getSize()) {
|
||||||
|
throw new FireflyException('Cannot upload empty or non-existent file.');
|
||||||
|
}
|
||||||
|
|
||||||
$content = $fileObject->fread($file->getSize());
|
$content = $fileObject->fread($file->getSize());
|
||||||
$encrypted = Crypt::encrypt($content);
|
$encrypted = Crypt::encrypt($content);
|
||||||
Log::debug(sprintf('Full file length is %d and upload size is %d.', \strlen($content), $file->getSize()));
|
Log::debug(sprintf('Full file length is %d and upload size is %d.', \strlen($content), $file->getSize()));
|
||||||
|
|||||||
@@ -342,6 +342,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
|||||||
* @param UploadedFile $file
|
* @param UploadedFile $file
|
||||||
*
|
*
|
||||||
* @return MessageBag
|
* @return MessageBag
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function storeFileUpload(ImportJob $job, string $name, UploadedFile $file): MessageBag
|
public function storeFileUpload(ImportJob $job, string $name, UploadedFile $file): MessageBag
|
||||||
{
|
{
|
||||||
@@ -374,6 +375,12 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
|||||||
$attachment->save();
|
$attachment->save();
|
||||||
$fileObject = $file->openFile('r');
|
$fileObject = $file->openFile('r');
|
||||||
$fileObject->rewind();
|
$fileObject->rewind();
|
||||||
|
|
||||||
|
|
||||||
|
if(0 === $file->getSize()) {
|
||||||
|
throw new FireflyException('Cannot upload empty or non-existent file.');
|
||||||
|
}
|
||||||
|
|
||||||
$content = $fileObject->fread($file->getSize());
|
$content = $fileObject->fread($file->getSize());
|
||||||
$encrypted = Crypt::encrypt($content);
|
$encrypted = Crypt::encrypt($content);
|
||||||
$this->uploadDisk->put($attachment->fileName(), $encrypted);
|
$this->uploadDisk->put($attachment->fileName(), $encrypted);
|
||||||
|
|||||||
Reference in New Issue
Block a user