Skip to content

Commit

Permalink
try catch when extracting metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Dec 7, 2024
1 parent cc3fb37 commit 1c91e6c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/Concerns/InteractWithFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,31 @@ public function putFile(
$this->extension = $extension;
$this->file_name = $fileName;

$dimension = File::dimension($file->getPathname());

$this->height = $dimension?->getHeight();
$this->width = $dimension?->getWidth();
$this->aspect_ratio = $dimension?->getRatio(forceStandards: false)->getValue();
$this->duration = File::duration($file->getPathname());
$this->mime_type = File::mimeType($file);
$this->size = $file->getSize();
$this->type = File::type($file->getPathname());

try {
$dimension = File::dimension($file->getPathname());
$this->height = $dimension?->getHeight();
$this->width = $dimension?->getWidth();
$this->aspect_ratio = $dimension?->getRatio(forceStandards: false)->getValue();
} catch (\Throwable $th) {
$this->height = null;
$this->width = null;
$this->aspect_ratio = null;
}

try {
$this->type = File::type($file->getPathname());
} catch (\Throwable $th) {
$this->type = MediaType::Other;
}

try {
$this->duration = File::duration($file->getPathname());
} catch (\Throwable $th) {
$this->duration = null;
}

return $path;
}
Expand Down

0 comments on commit 1c91e6c

Please sign in to comment.