<?php
namespace OfficeBrain\Bundle\CoreBundle\File;

use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class ApiUploadedFile extends UploadedFile
{
    public function __construct($base64Content,$originalName)
    {
        $filePath = tempnam(sys_get_temp_dir(), 'UploadedFile');
        $file = fopen($filePath, "w");
        stream_filter_append($file, 'convert.base64-decode');
        fwrite($file, $base64Content);
        $meta_data = stream_get_meta_data($file);
        $path = $meta_data['uri'];
        fclose($file);
        
        /* $f = finfo_open();   
        $imgdata = base64_decode($base64Content);
        $mime_type = finfo_buffer($f, $imgdata, FILEINFO_MIME_TYPE);
        finfo_close($f); */
        $finfo = finfo_open(FILEINFO_MIME_TYPE);        
        $mime_type = finfo_file($finfo, $path);
        finfo_close($finfo);
        //$mime_type = mime_content_type($path);// as it is deprecated 
        //$size = @getimagesize($path);
        $size = filesize($path);
        
        parent::__construct($path, $originalName, $mime_type, $size, null, true);
    }
}