-
Hello, We're uploading some files via base64, the mime-type of the file isn't known at the point of upload but is of course encoded in the base64. Unfortunately, medialibrary doesn't set the file extension correctly when adding media via The problem I have is I cannot get the mime-type of the file as the FileAddr created by I've noticed multiple recorded issues and discussion around this point and the answer provided is always use It seems to me that given e.g.: This works great if the base64 encode is actually a
Whereas the following results in the file being called
And the below updates the file with the correct extension, but requires another database query, and another hit against the storage device, it is also recommended to set The problem with this is if all you do is change the extension and not the path, the
None of these are practical solutions, it would be so much simpler if Unless I'm missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Feel free to make a PR |
Beta Was this translation helpful? Give feedback.
-
My work around above no longer works as of 01/03/2023 I don't know if it's because I upgraded to v10 of medialibrary or if AWS changed something with S3. But since then, calling save() on $avatar to rename the file_name causes conversions to run resulting in the following error:
|
Beta Was this translation helpful? Give feedback.
-
My workaround. I simply overwrote InteractsWithMedia trait. use Spatie\MediaLibrary\InteractsWithMedia as BaseInteractsWithMedia;
trait InteractsWithMedia
{
use BaseInteractsWithMedia;
public function addMediaFromBase64(string $base64data, array|string ...$allowedMimeTypes): FileAdder
{
// ...
$fileInfo = finfo_open();
$mime_type = finfo_buffer($fileInfo, $binaryData, FILEINFO_EXTENSION);
$tmpFile = tempnam(sys_get_temp_dir(), 'media-library').".$mime_type";
// ...
}
} |
Beta Was this translation helpful? Give feedback.
My workaround. I simply overwrote InteractsWithMedia trait.