问题描述
我正在使用Dropzone使用Laravel 5上传图像。在Dropzone对我的URL进行put调用后,出现以下错误:
I am using Dropzone to upload images using Laravel 5. After Dropzone makes the put call to my URL I get the following error:
但是,当我查看请求的有效负载时,令牌就存在了:
However, when I look at the payload for the request the token is present:
PUT
------ WebKitFormBoundary91A7BYrMsDcGTEvx Content-Disposition:表单数据; name = _ token
PUT ------WebKitFormBoundary91A7BYrMsDcGTEvx Content-Disposition: form-data; name="_token"
j3NbjibYF7k8g2w1P0enw6YVfDrDvCGKFMCFtt4NX
------ WebKitFormBoundary91A7BYrMsDcGTEvx内容处理:表单数据; name = title
j3NbjibYF7k8g2w1P0enw6YVfDrDvCGKFMCFt4NX ------WebKitFormBoundary91A7BYrMsDcGTEvx Content-Disposition: form-data; name="title"
这是我的JS:
Dropzone.options.realDropzone = {
url: '/user/manage/10',
method: 'PUT',
paramName: 'file',
uploadMultiple: false,
parallelUploads: 100,
previewsContainer: '#dropzonePreview',
addRemoveLinks: true,
maxFiles: 10,
autoProcessQueue: false,
init: function () {
var dropZone = this;
this.element.querySelector("#save").addEventListener("click", function (e) {
e.preventDefault();
e.stopPropagation();
console.log("clicked submit");
dropZone.processQueue();
});
},
};
我的表单:
{!! Form::model($asset, ['method' => 'PUT', 'class' => 'dropzone', 'id' => 'real-dropzone', 'action' => ['UserManagementController@update', $asset->id], 'file' => true]) !!}
我的控制器:
public function update(Request $request, $id)
{
return dd(FileRequest::file('file'));
}
推荐答案
尝试在以下位置添加令牌您的Dropzone选项:
Try to add the token in your Dropzone options:
sending: function(file, xhr, formData) {
formData.append("_token", "{{ csrf_token() }}");
},
这篇关于Dropzone CSRF令牌不匹配Laravel 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!