v-uploader
v-uploader copied to clipboard
How to Pass CSRF token for Laravel Upload Ajax request?
Getting 419 error. How to Pass CSRF token for Laravel Upload Ajax request?
@devravik
Using v-bind to replace the upload url works for me:
<v-uploader @done="uploadDone" v-bind:upload-file-url="'{{ '/foo/file-upload?_token=' . csrf_token() }}'"></v-uploader>
如果使用组件的 可以这样实现
1 在 blade 中 <meta name="csrf-token" content="{{ csrf_token() }}">
2 在 app.js 中
var csrf_token = document.querySelector('meta[name=csrf-token]').getAttribute('content');
const uploaderConfig = {
uploadFileUrl: 'api/upload/publicFileUpload?_token='+csrf_token,
fileTypeExts: "jpeg,jpg,png",
showMessage: (vue, message) => {
vue.$dlg.alert(message);
}
};
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
Try this.. Hope it will help you