Imgur image uploading through api not working

I’m trying to build a blog website, so I wanted to upload images to imgur and retrieve the link for the image. But when I try to upload image using the below code, the images are not uploading. Is there anything wrong in my code? Or is there any better way to do the same?

This is the code that I’m using.

<input type="file" accept="image/*">


        <script src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.js'></script>
        <script type="text/javascript">
            $('document').ready(function () {
            $('input[type=file]').on('change', function () {
                var $files = $(this).get(0).files;

                if ($files.length) {
                // Reject big files
                if ($files[0].size > $(this).data('max-size') * 1024) {
                    console.log('Please select a smaller file');
                    return false;
                }

                // Begin file upload
                console.log('Uploading file to Imgur..');

                // Replace ctrlq with your own API key
                var apiUrl = 'https://api.imgur.com/3/image';
                var apiKey = 'b985f2a2610584c';

                var settings = {
                    async: false,
                    crossDomain: true,
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    url: apiUrl,
                    headers: {
                    Authorization: 'Client-ID ' + apiKey,
                    Accept: 'application/json',
                    },
                    mimeType: 'multipart/form-data',
                };

                var formData = new FormData();
                formData.append('image', $files[0]);
                settings.data = formData;

                // Response contains stringified JSON
                // Image URL available at response.data.link
                $.ajax(settings).done(function (response) {
                    console.log(response);
                });
                }
            });
            });
        </script>

Btw i’m using flask to build my website.
Thanks in advance.