danielm / uploader

A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
https://danielmg.org/demo/java-script/uploader
MIT License
1.17k stars 384 forks source link

Token Mismatch With Laravel #31

Closed derrandz closed 6 years ago

derrandz commented 9 years ago

I switched from dropzone to this and I like it, however I thuoght I could manipulate the ajax data sending how I wanted, which seems to not be true.

Laravel forms need a csrf token to be verified.

Although I have it in my form, I still did get the 'tokenMisMatch' error, which made me conclude that this plugin does send only files input...

How do I manipulate the request to take all of the forms input, and send it onclick, and autoqueued as is here by default?

I believe it is via the extraData option... but how?

edward-buskus commented 9 years ago

Hi, i think this will help you $("#drop-area-div").dmUploader({ url: '/upload/image', extraData: { _token:'{{ csrf_token() }}' }} );

derrandz commented 9 years ago

So there is an extraData indeed, I'll retry with that bug when time is allowing, thank you.

blenderdeluxe commented 7 years ago

Hey @jshrt and @etmind I dont have any problem using this

$(document).ready(function(){

    $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
    });
});

and I have in my the meta tag

<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">

so you dont need use extraData I know that this issue is time time ago haha but maybe this help to others!! :D

regards!

derrandz commented 7 years ago

I do not remember when this was exactly, but I'll definitely go with a header specification rather than some other attribute that is specific to a component.

Thanks @blenderdeluxe

danielm commented 6 years ago

Closing the issue.

With the new release there is a new headers option to provide something like this.

In addition to that, extraData can now be a function itself and return a collection of data too. Use-full for dynamic values that may change each request.

extraData: function(){
    return {
      galleryid: $('#albumPicker').val();
   };
}