0

I'm trying to implement file pasting in the browser using the following code

document.onpaste = function (event) {
    for (var item of event.clipboardData.items) {
        if (item.kind == 'file')
            process(item.getAsFile());
    }
};

But I didn't get the file I pasted. Logging the DataTransferItem object item I noticed that its kind is not file but always string and it's a list of the copied files' names. Is there a problem in my code or this issue is related to my platform ? I am working with Firefox 104.0, Ubuntu 22.04 and Wayland

glk0
  • 17
  • 6
  • This is quite remarkable timing - I've just added this question/answer: https://stackoverflow.com/questions/73776453/how-do-i-accept-file-uploads-from-pasting-data-into-the-browser/73776454 – Richard Sep 19 '22 at 16:22
  • Is it working on your side ? I'm persuaded that this is a problem with my setup but I don't have another machine with a different setup to check. – glk0 Sep 20 '22 at 18:01
  • Yes - just copy the src code into a file on your PHP-enabled web server and access it thru your website. – Richard Sep 20 '22 at 18:23

0 Answers0