Php dropzone未上载,400错误请求,未提供令牌
好吧,我已经试了2个小时了,但我不能让它工作。dropzone无法上载任何文件。服务器显示“未提供令牌”。im使用laravel作为后端,使用jwt令牌进行身份验证,使用angular作为前端。这是我的dropzone配置Php dropzone未上载,400错误请求,未提供令牌,php,angularjs,Php,Angularjs,好吧,我已经试了2个小时了,但我不能让它工作。dropzone无法上载任何文件。服务器显示“未提供令牌”。im使用laravel作为后端,使用jwt令牌进行身份验证,使用angular作为前端。这是我的dropzone配置 $scope.dropzoneConfig = { options: { // passed into the Dropzone constructor url: 'http://localhost:8000/api/attachments'
$scope.dropzoneConfig = {
options: { // passed into the Dropzone constructor
url: 'http://localhost:8000/api/attachments'
paramName: 'file'
},
eventHandlers: {
sending: function (file, xhr, formData) {
formData.append('token', TokenHandler.getToken());
console.log('sending');
},
success: function (file, response) {
console.log(response);
},
error: function(response) {
console.log(response);
}
}
};
以及路线定义
Route::group(array('prefix' => 'api', 'middleware' => 'jwt.auth'), function() {
Route::resource('attachments', 'AttachmentController', ['only' => 'store']);
}));
以及控制器方法
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$file = Input::file('file');
return 'okay'; // just until it works
}
令牌是正确的,并且实际上正在到达服务器(因为我尝试在另一个控制器函数中使用Input::get('token')返回令牌,并且它可以工作)。有人能告诉我我做错了什么吗?我收到“400错误请求”和“未提供令牌”消息。。。
谢谢你的帮助。我很抱歉我的英语不好。我不知道为什么将令牌附加到表单中不起作用,但您可以尝试将其发送到授权标头中 替换
formData.append('token', TokenHandler.getToken());
与
确保将令牌添加到调用中:例如,您可以将toke作为参数添加到dropzone url参数中
//If you are using satellizer you can you this
var token = $auth.getToken();// remember to inject $auth
$scope.dropzoneConfig = {
options: { // passed into the Dropzone constructor
url: 'http://localhost:8000/api/attachments?token=token'
paramName: 'file'
},
eventHandlers: {
sending: function (file, xhr, formData) {
formData.append('token', TokenHandler.getToken());
console.log('sending');
},
success: function (file, response) {
console.log(response);
},
error: function(response) {
console.log(response);
}
}
};
//If you are using satellizer you can you this
var token = $auth.getToken();// remember to inject $auth
$scope.dropzoneConfig = {
options: { // passed into the Dropzone constructor
url: 'http://localhost:8000/api/attachments?token=token'
paramName: 'file'
},
eventHandlers: {
sending: function (file, xhr, formData) {
formData.append('token', TokenHandler.getToken());
console.log('sending');
},
success: function (file, response) {
console.log(response);
},
error: function(response) {
console.log(response);
}
}
};