Hi I want to pass formdata with input type file but how can I do it?

I have this function when I change the input type file to insert into database, in Laravel.

$(document).on('change', '#galeria_imagen', function () {
var elab = $('#elaboracion_ins').val();
var formdata = new FormData();

formdata.append("galeria_imagen", $('input[name=galeria_imagen]')[0].files[0]);

console.log(prueba);
$.ajax({
    type: 'POST',
    url: "/admin/elaboraciones/ajax/setGaleria",
    processData: false,
    data: formdata,
    success: function () {
        recargar_galeria(elab);
    }
});

});

And always return me “Illegal invocation” and I put ProcessData:false and don’t work for me because don’t insert, in Laravel I need a base64 hash to insert a file.

#php #laravel- #jquery #ajax

3 Likes6.55 GEEK