Firefox treating pasted image from clipboard as a string instead of file

127
March 17, 2022, at 4:40 PM

I am trying to get image from on paste event from a contenteditable div. It is working fine in chrome but isn't working in firefox. I am using the following code:

$(window).on("paste", function(e) {
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];
    if(e.originalEvent.clipboardData.items.length!=0)
    {
        let file = e.originalEvent.clipboardData||e.clipboardData).items[0].getAsFile();
            var upload_url = "{% url 'api:v2:images:upload' %}?format=json";
            if (file)
            {
                var fileType = file['type'];
                if (validImageTypes.includes(fileType)) {
                    var data = new FormData();
                    data.append('qqfile', file);
                    $.ajax({
                            type: 'POST',
                            processData: false, // important
                            contentType: false, // important
                            data: data,
                            url: upload_url,
                            dataType : 'json',
                            async: false,
                            success: function(jsonData){
                                var new_tag = "<img src=\""+jsonData.url+"\" data-verified=\"redactor\" data-save-url=\""+jsonData.filelink+"\" style=\"opacity: 0.5;\">";
                                 setTimeout(insertTextAtCaret(new_tag),0);
                             }
                         });
                }
                e.preventDefault();
            }
        }
     });

e.originalEvent.clipboardData.items[0] contains data of type text/plain in firefox whereas, it is image/png in chrome. (For a png image upload) `

Rent Charter Buses Company
READ ALSO
Run search function on each keypress

Run search function on each keypress

I have this function that when I click on submit or press Enter that uses the value in the input and scans for it in the child of each div, and if it finds one it hides all and shows only that div

116
How to save custom color on localStorage jquery?

How to save custom color on localStorage jquery?

I` have a function in jquery witch allow users to change background color of siteBut if they refresh the page background-color go to default

130
jquery years months and days variable

jquery years months and days variable

when the system appears, I see that it is very complicated, but I have a problem, I found this code from somewhere, but I am writing because I do not have much knowledge, thank you in advance to those who help

96
Jquery Confirm a form after Validation

Jquery Confirm a form after Validation

I have a html form which I validate with JqueryWhat I want to do now is to let the user review his form and to confirm sending the form after it was validatet by jquery

154