首页 > 解决方案 > 为什么图像验证接受文本文件 laravel postman?

问题描述

我正在使用 laravel 8,我正在从邮递员上传文件。我还为 png、jpeg 和 jpg 编写了验证规则。但是当我选择任何其他文件时,它也会上传它。邮递员中的表单数据在 此处输入图像描述

我的验证资源文件是

public function rules()
{
    return [
        'invoice_id' => ['required', 'string'],
        'invoice_date' => ['required', 'date'],
        'invoice_photo_url' => ['required','image','mimes:jpeg,png,jpg'],
        'invoice_net_total' => ['required','regex:/^\d*(\.\d{1,2})?$/'],
    ];
}

我的控制器方法是

public function upload(InvoiceUploadRequest $request)
{
    try {
        return $this->responseWithSuccess(true,"Invoice successfully uploaded!",
            $this->invoiceInterface->uploadInvoice($request), Response::HTTP_OK);
    }catch (\Exception $exception){
        return $this->responseWithError($exception->getMessage(), Response::HTTP_OK);
    }
}

怎么能解决这个问题。谢谢

标签: laravelapifile-uploadpostmanlaravel-validation

解决方案


推荐阅读