Skip to content

Commit

Permalink
fix validation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-aliraqi committed May 7, 2022
1 parent 91aa241 commit d0f1c68
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Rules/MediaRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(...$types)
*/
public function passes($attribute, $value)
{
if (! $value instanceof UploadedFile) {
if (! $value instanceof UploadedFile && ! $this->isBase64($value)) {
return false;
}

Expand Down Expand Up @@ -68,6 +68,10 @@ public function message()
*/
protected function getTypeString($value): string
{
if ($this->isBase64($value)) {
return 'image';
}

$fileFullPath = $value->getRealPath();

if ((new Image())->canHandleMime($value->getMimeType())) {
Expand All @@ -80,10 +84,6 @@ protected function getTypeString($value): string
)));
}

if (is_string($value) && base64_decode(base64_encode($value)) === $value) {
$type = 'image';
}

return $type; // either: image, video or audio.
}

Expand All @@ -96,4 +96,15 @@ protected function documentsMimeTypes()
{
return Config::get('laravel-media-uploader.documents_mime_types');
}

/**
* Determine whither the value is base64 image.
*
* @param $value
* @return bool
*/
protected function isBase64($value)
{
return is_string($value) && base64_decode(base64_encode($value)) === $value;
}
}

0 comments on commit d0f1c68

Please sign in to comment.