Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

md_imran's avatar

How to make image file an instance of uploadFile?

Hello Artisans,

In my project, I am working with image taken by live cam. Libraray is webcam js.

like I am getting this format for image

 [image] => data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYI......

but I need this format,

 [image] => Illuminate\Http\UploadedFile Object
        (
            [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 
            [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => sohid-mollah.jpeg
            [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
            [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
            [hashName:protected] => 
            [pathName:SplFileInfo:private] => /tmp/phprzfG0R
            [fileName:SplFileInfo:private] => phprzfG0R
        )

can you give a concept?

0 likes
5 replies
CorvS's avatar

@md_imran Okay, have you checked the docs? Especially the part mentioned above.

martinbean's avatar

@md_imran You can’t, because it’s not a file; it’s Base64-encoded data. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs for more details.

You can parse the URI and then store the data yourself:

[$mime, $contents] = explode(';', $request->input('image'));

// Remove "mime:" from beginning of string
$mime = str_replace('mime:', '', $mime);

// Remove "base64," from beginning of data
$contents = str_replace('base64,', '', $contents);

Storage::put('some-filename.jpg', $contents, [
    'Content-Type' => $mime,
]);

Please or to participate in this conversation.