Laravel 7 Incorrect MIME Type Detected

爷,独闯天下 提交于 2021-02-10 22:16:58

问题


Laravel 7 on PHP 7 is detecting incorrect MIME type of application/octet-stream for .ogg extension.

Here is the applicable file request dump:

Illuminate\Http\UploadedFile {#1274 ▼
  -test: false
  -originalName: "03 - See You Tonite.ogg"
  -mimeType: "application/octet-stream"

Anybody know of a workaround for this?


回答1:


Check your mime type file first:

 return $request->file('field_name')->getMimeType();

Now you can add the following code in the boot method in AppServiceProvider:

public function boot()
    {
       
        Validator::extend('ogg_extension', function($attribute, $value, $parameters, $validator) {
             
            if(!empty($value->getClientOriginalExtension()) && ($value->getClientOriginalExtension() == 'ogg')){
                return true;
            }else{
                return false;
            }
             
        });
    }


来源:https://stackoverflow.com/questions/63538962/laravel-7-incorrect-mime-type-detected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!