mercredi 12 mai 2021

Image upload in ajax and get base64 data

I am trying to upload image using ajax in laravel. Here is my code

<input type="file" name="item_image" class="form-control item_image">
<button type="button" class="btn btn-primary store_new_item"> Save </button>

Ajax

$(document).on('click', '.store_new_item', function () {
var item_name = $('.item_name').val();

var data = new FormData();  
data.append('file', $('.item_image')[0].files[0]);
var size  =  $('.item_image')[0].files[0].size;
console.log(data);

$.ajax({
    url: '',
    type: "POST",
    enctype: 'multipart/form-data',
    //dataType: 'json',
    headers: {
        'X-CSRF-TOKEN': ''
    },
    data: {
        item_name: item_name,
        item_image: data
    },

Laravel

  $item_image = base64_encode($request->get('item_image'));

It shows error Uncaught TypeError: Illegal invocation in console how can i get base64 data in controller ? Thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/33FnJgg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire