Skip to content

base64 mimetype and file extensions #3089

Answered by layerok
SlyDave asked this question in Q&A
Discussion options

You must be logged in to vote

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";
        // ...
    }
}

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@SlyDave
Comment options

@angeljqv
Comment options

@SlyDave
Comment options

@PaolaRuby
Comment options

@SlyDave
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by SlyDave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants