UnableToRetrieveMetadata error

This commit is contained in:
Čarodej
2022-05-10 07:53:41 +02:00
parent b6cf1e2799
commit 5d7fed7de8
2 changed files with 27 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ use Domain\Files\Models\File;
use Illuminate\Support\Facades\Storage;
use Domain\Files\Requests\UploadRequest;
use Domain\Traffic\Actions\RecordUploadAction;
use League\Flysystem\UnableToRetrieveMetadata;
class ProcessFileAction
{
@@ -26,18 +27,28 @@ class ProcessFileAction
UploadRequest $request,
User $user,
string $name,
) {
): File {
// Get local disk instance
$localDisk = Storage::disk('local');
// Get file path
$filePath = "files/$user->id/$name";
// Get file data
// Get file size
$size = $localDisk->size($filePath);
$mimetype = $localDisk->mimeType($filePath);
// Get upload limit
// Get upload limit size
$uploadLimit = get_settings('upload_limit');
// Get mimetype
try {
$fileType = getFileType(
$localDisk->mimeType($filePath)
);
} catch (UnableToRetrieveMetadata $e) {
$fileType = 'file';
}
// File size handling
if ($uploadLimit && $size > format_bytes($uploadLimit)) {
abort(413);
@@ -57,11 +68,13 @@ class ProcessFileAction
);
}
// Create multiple image thumbnails
($this->createImageThumbnail)($name, $user->id);
if ($fileType === 'image') {
// Create multiple image thumbnails
($this->createImageThumbnail)($name, $user->id);
// Store exif data if exists
$exif = ($this->storeExifData)($filePath);
// Store exif data if exists
$exif = ($this->storeExifData)($filePath);
}
// Move file to external storage
match (config('filesystems.default')) {
@@ -73,7 +86,7 @@ class ProcessFileAction
// Create new file
$file = File::create([
'mimetype' => $request->input('extension'),
'type' => getFileType($mimetype),
'type' => $fileType,
'parent_id' => ($this->getFileParentId)($request, $user->id),
'name' => $request->input('name'),
'basename' => $name,
@@ -83,7 +96,10 @@ class ProcessFileAction
]);
// Attach file into the exif data
$exif?->update(['file_id' => $file->id]);
if ($fileType === 'image') {
$exif?->update(['file_id' => $file->id]);
}
// Return new file
return $file;