Level 11
is your file input named 'file' ?
<input type="file" name="file" />
Hello,
I'm trying to upload a file through ajax(angular's $http). Here's my code:
Validator:(SomeRequest)
public function rules() {
return [
'text' => 'required',
'file' => 'mimes:jpeg,bmp,png,jpg,psd,gif'
];
}
Controller:
public function some(SomeRequest $request) {
dd( $request->all());
}
Javascript:
$http({
data: {text: form.text, file: form.file[0]},
method: 'POST',
url: '/upload/',
headers: {
'X-CSRF-TOKEN': CSRF_TOKEN
}
})
When I submit a form it sends request, it returns:
The file must be a file of type: jpeg,bmp,png,jpg,psd,gif
When I do dd($this->file) in rules function it returns:
array:6 [
"webkitRelativePath" => ""
"lastModified" => 1425727607319
"lastModifiedDate" => "2015-03-07T11:26:47.319Z"
"name" => "some.png"
"type" => "image/png"
"size" => 27807
]
So it seems to be ok.(or not?)
What am I doing wrong? Thanks.
Please or to participate in this conversation.