View Source PlugMimeTypeCheck (Plug Mime Type Check v0.1.2)
A plug that checks the mime-type of a uploaded file through a request
It requires an option:
:allowed_mime_types- a list of allowed file mime types for the route. It must be a list.
To use you can just plug in your controller and it will work to all your actions.
You must pass the :allowed_mime_types list, for example:
plug PlugMimeTypeCheck, allowed_mime_types: ["text/csv", "image/*"]You can apply just to defined actions, for example:
plug PlugMimeTypeCheck, [allowed_mime_types: ["application/pdf"]] when action in [:create, :update]Or you can plug in your router.ex file:
pipeline :uploads do
plug PlugMimeTypeCheck, allowed_mime_types: ["image/png"]
end
scope "/api", MyModuleWeb do
pipe_through :uploads
post "/upload", UploadController, :upload
end