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

问题描述 投票:0回答:1

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

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),
    ];
}

enter image description here

JSON内容

{
    "name":"test"
}
laravel validation request mime-types
1个回答
0
投票

您确定您实际上是在上传具有application/json模拟类型的文件吗? .json扩展名不会自动表示为application/json。另请注意documentation中的以下内容:

要确定上载文件的MIME类型,将读取文件的内容,并且框架将尝试猜测MIME类型,这可能与客户端提供的MIME类型不同。

© www.soinside.com 2019 - 2024. All rights reserved.