ardi ws
ardi ws

Reputation: 21

How can i save data from HTML img tag in laravel

I have a form include image, this image i get from webcam and store it to img tag, how can i save data from attribute src, usually to store file using upload file.

<img id="myImage" src="data:image/png;base64,IvBo9Vraf...." alt="image from snapshot" />

I have read similar questions but not as i expected

Upvotes: 2

Views: 498

Answers (1)

Prathamesh Doke
Prathamesh Doke

Reputation: 845

With this code you can saved the files.

 $filename = $request->file('myFile')->store('files');
 $data= new FileModel();
 $data->file = $filename;
 $data->save();

or you can try below method

        $myImage = $request->file('myFile');
        if(!in_array($myImage->getMimeType(), ['image/jpeg', 'image/png'])){
            abort(500, 'Unsupported Image Type');
        }
        $imageName = str_replace('myImages/', '', $myImage->store('myFile'));
        return ['my_image'=>$profile_picture_name];

Upvotes: 1

Related Questions