diff --git a/services/nginx/app/traits/minio_t.php b/services/nginx/app/traits/minio_t.php index 9f335f84..7ae78bc0 100644 --- a/services/nginx/app/traits/minio_t.php +++ b/services/nginx/app/traits/minio_t.php @@ -198,11 +198,17 @@ trait minio_t public function storeTempFileFromBase64(string $base64, string $fileExtension = 'txt'): string|bool { // Check if the base64 string is valid - if (empty($base64) || !preg_match('/^data:.*;base64,/', $base64)) { + if (empty($base64)) { return false; // Invalid base64 string } + + // Check if the base64 string has a data URI prefix + if (preg_match('/^data:.*;base64,/', $base64)) { + $base64 = preg_replace('/^data:.*;base64,/', '', $base64); + } + // Decode the base64 data - $fileData = base64_decode(preg_replace('/^data:.*;base64,/', '', $base64)); + $fileData = base64_decode($base64); if ($fileData === false) { return false; // Failed to decode base64 data } @@ -236,11 +242,16 @@ trait minio_t public function storeTempImageFromBase64(string $base64): string|bool { // Check if the base64 string is valid - if (empty($base64) || !preg_match('/^data:image\/(\w+);base64,/', $base64)) { + if (empty($base64)) { return false; // Invalid base64 string } - // Extract the base64 data from the string - $imageData = preg_replace('/^data:image\/\w+;base64,/', '', $base64); + + // Extract the base64 data from the string if it has a data URI prefix + $imageData = $base64; + if (preg_match('/^data:image\/(\w+);base64,/', $base64)) { + $imageData = preg_replace('/^data:image\/\w+;base64,/', '', $base64); + } + // Decode the base64 data $imageData = base64_decode($imageData); if ($imageData === false) {