为什么检查 json mimetype 在我的请求中不起作用?

Why is checking for a json mimetype not working in my Request?

我有一个 Laravel API 并且我发出自定义请求来验证值。我正在通过 Postman 测试我的路线,并在我的设置字段中添加了一个 JSON 文件。但是,当我尝试验证自定义请求中的 mimetype 时,会抛出错误。当我删除 |mimetypes:application/json 路由时 returns 成功响应。为什么会这样?

public function rules()
{
    return [
        'name' => 'required|string|min:2|max:32|unique:game_templates',
        'path' => 'required|string|url|unique:game_templates', 
        'settings' => 'required|file|mimetypes:application/json',
        'orientation' => Rule::in(GameTemplate::$orientations),
    ];
}

JSON内容

{
    "name":"test"
}

你确定你上传的是 application/json mime 类型的文件吗? .json 扩展名并不自动意味着它是 application/json。另请注意 documentation 中的以下内容:

To determine the MIME type of the uploaded file, the file's contents will be read and the framework will attempt to guess the MIME type, which may be different from the client provided MIME type.