Adding an image chooser to a Magento 2 widget

In the previous post we have described how to add a new widget in Magento 2. As it was mentioned, each widget field has its own input type. The input type allows determining what graphical interface component will be used to represent this field. Magento 2 has a set of simple input types out of the box such as input field, dropdown etc. Also, it has more complex components: products chooser, rules conditions component, CMS block chooser and others. But in some cases you need to add your own input type, for example if you want to allow choosing an image from media gallery in your widget configuration. In this post we review how to add an image chooser/uploader to your widget.