Laravel - Save div image to file?

Asked

Viewed 57 times

0

I need to assemble a form (blade) where I glue an image, I use javascript and it works without problems, but when I try to recover this image in controller, the data are not passed.

In the HTML am using CANVAS:

<canvas class="imagem" id='imagem' width="1200" height="400" id="canvas"></canvas>

In Javascript when I try to save:

<script>
    <!--
    function exportCanvas(form){
        var canvas = document.getElementById('imagem');
        var dataURL = canvas.toDataURL();

        alert(dataURL);
        $.ajax({
            type: "POST",
            url: "/imagem",
            data: { 
                imgBase64: dataURL
            }
        }).done(function(o) {
            console.log('saved'); 
            // Do here whatever you want.
        });

        //form.submit;
    }
    -->  
</script>

In my controller:

$data = $request->imgBase64; 

but the variable $data presents value null.

  • How’s your controller code?

  • <?php namespace App Http Controllers; use Illuminate Support Facades Auth; use Illuminate Http Request; use Illuminate Support Facades URL; use Illuminate Support Facades DB; class Imagemcontroller extends Controller { public Function index(Request $request) { Return view('image.image'); } public Function Edit(Request $request) { // $capture = $request->capture; $data = $request->imgBase64; // $image = Image::make($request->get('imgBase64')); var_dump($data); } Return '; }

  • The code in the controller is pretty simple, just so I can check if the data has been passed.

  • What happens when you display the request content? Example: var_dump($request->all());

  • When I run a var_dump() the value it shows on the screen is null.

  • Strange... try to change the method ajax for $.post('/imagem', { imgBase64: dataURL });

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.