javascript - Pasting from a file browser and HTML5 Clipboard API - Stack Overflow

I'm trying to add an image paste function to my web application, using the standard routine:$(

I'm trying to add an image paste function to my web application, using the standard routine:

$('textarea').on('paste', function (ev) {
    var clipboardData = ev.originalEvent.clipboardData;

    $.each(clipboardData.items, function (i, item) {
        if (item.type.indexOf("image") !== -1) {
            var reader = new FileReader();

            reader.readAsDataURL(item.getAsFile());
            reader.addEventListener('loadend', ...);
            ...
        }
    });
});

The full sample can be found here: /

It works correctly when I copy & paste an image from an image viewer software, but when I'm trying to do the same thing using a file browser (e.g. Finder on Mac or Nautilus on Linux) as a result I get only a text string with the file path or even an image with file type icon instead of an original file.

Is there any way to handle pastes from a file browser properly?

I'm trying to add an image paste function to my web application, using the standard routine:

$('textarea').on('paste', function (ev) {
    var clipboardData = ev.originalEvent.clipboardData;

    $.each(clipboardData.items, function (i, item) {
        if (item.type.indexOf("image") !== -1) {
            var reader = new FileReader();

            reader.readAsDataURL(item.getAsFile());
            reader.addEventListener('loadend', ...);
            ...
        }
    });
});

The full sample can be found here: http://jsfiddle/t8t2zj6k/

It works correctly when I copy & paste an image from an image viewer software, but when I'm trying to do the same thing using a file browser (e.g. Finder on Mac or Nautilus on Linux) as a result I get only a text string with the file path or even an image with file type icon instead of an original file.

Is there any way to handle pastes from a file browser properly?

Share Improve this question asked Apr 18, 2015 at 19:03 NikitaBaksalyarNikitaBaksalyar 2,5141 gold badge24 silver badges27 bronze badges 4
  • Possibly this could help you? stackoverflow./questions/6333814/… – lemieuxster Commented Apr 18, 2015 at 22:34
  • @lemieuxster, thanks, but unfortunately I'm already using the exact same solution provided in the accepted answer. My case is a bit different - while the basic paste function is working well, there's an issue with pasting from Finder. – NikitaBaksalyar Commented Apr 18, 2015 at 22:50
  • Seems to maybe be an issue with Chrome? I don't see anything in Safari or Firefox. code.google./p/chromium/issues/detail?id=361980 – lemieuxster Commented Apr 18, 2015 at 23:19
  • @lemieuxster, thank you! The bug report totally explains this weird behavior. Perhaps you should add it as an answer to the question so that I can accept it? – NikitaBaksalyar Commented Apr 18, 2015 at 23:37
Add a ment  | 

2 Answers 2

Reset to default 3

Seems to maybe be an issue with Chrome? I don't see anything in Safari or Firefox. http://code.google./p/chromium/issues/detail?id=361980

Maybe you would like to paste image as data:

Go look at HTML5 paste image to page

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742295605a4417053.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信