【发布时间】:2020-11-05 12:51:14
【问题描述】:
似乎某些 ios 设备(我相信是较新的 iPhone 和 iPad)和版本无法正确验证文件。 我正在尝试验证一张图片、一份简历和 3 个视频。
我不断收到以下两个错误之一:
"resume_id": [
"The resume id must be a file of type: doc, docx, pdf."
]
而且我总是上传 .doc 或 pdf 文件。
或者
"video_one_id": [
"The video one id must be a file of type: avi ,mpeg, mpeg4, mov."
]
"video_two_id": [
"The video two id must be a file of type: avi ,mpeg, mpeg4, mov."
]
"video_three_id": [
"The video three id must be a file of type: avi ,mpeg, mpeg4, mov."
]
而且我总是上传 .mov 文件。我发现当我在 iPhone 上拍摄视频并上传时,通常会发生这种情况。我的客户也在他全新的 iPad 上尝试过同样的事情,但也没有成功。
这是我的代码。
CandidateProfileRequest.php:
public function rules()
{
return [
'date_of_birth' => 'required',
'experience' => [
'required',
new MaxWordsRule(),
],
'skills' => [
'required',
new MaxWordsRule(350),
],
'job_title' => 'required',
'resume_id' => 'required|file|mimes:doc,docx,pdf',
];
}
CandidateProfileController.php:
public function store(CandidateProfileRequest $request)
{
if ($request->hasFile('video_one_id')
&& $request->hasFile('video_two_id')
&& $request->hasFile('video_three_id')
&& $request->hasFile('photo_id')) {
$request->validate([
'video_one_id' => 'file|mimes:avi ,mpeg, mpeg4, mov|max:30720',
'video_two_id' => 'file|mimes:avi ,mpeg, mpeg4, mov|max:30720',
'video_three_id' => 'file|mimes:avi ,mpeg, mpeg4, mov|max:30720',
'photo_id' => 'image|mimes:jpeg, png, jpg|max:5120'
]);
}
}
我还尝试在我的验证规则中使用 mimetypes 而不是 mime,但仍然出现上述错误。 在我的 Macbook Pro 笔记本电脑上一切正常,只在我的 iPhone 和我的客户 iPad 上运行。
我做错了什么?
【问题讨论】:
标签: laravel file validation