How to include the CSRF token in the headers in Dropzone upload request?

前端 未结 9 1824
难免孤独
难免孤独 2020-12-13 18:19

I am working on a single page application and I am using Laravel 5 for the web service.

All forms are submitted asynchronously and I use a beforeSend on them to atta

9条回答
  •  旧巷少年郎
    2020-12-13 18:52

    Okay so this code is working just fine now:

    $("#mydropzone").dropzone({
        url: "/profile/update-photo",
        addRemoveLinks : true,
        maxFilesize: 5,
        dictDefaultMessage: ' Drop files to upload  

    (Or Click)

    ', dictResponseError: 'Error uploading file!', headers: { 'X-CSRF-TOKEN': $('meta[name="token"]').attr('content') } });

    So basically I needed to add the X-CSRFToken in the header of the Dropzone request. Works like charm now.

提交回复
热议问题