javascript - Copy and paste images from clipboard, blob Error -
i'm trying copy , paste images clipboard, error message in chrome. wrong?
error
uncaught typeerror: failed execute 'readasdataurl' on 'filereader': argument not blob. js
$(function() { $("body").bind("paste", function(ev) { var $this = $(this); var original = ev.originalevent; var file = original.clipboarddata.items[0].getasfile(); var reader = new filereader(); reader.onload = function (evt) { var result = evt.target.result; var arr = result.split(","); var data = arr[1]; // raw base64 var contenttype = arr[0].split(";")[0].split(":")[1]; // needs post server route can accept raw base64 content , save file $.post("/echo/html/", { contenttype: contenttype, data: data }); $this.append("<img src='" + result + "' />"); }; reader.readasdataurl(file); }); });
you're problem that, when browser trying load file through clipboard, looking blob type of data.
blob, or b inary l arge ob ject lengthy string object, instead of being file, string.
by trying copy clipboard, has copy of directory of file, @ least how error , how code is, that's looks like, isn't blob file type, chrome isn't set handle actual file.
i don't know for, if trying save files on database, should have image uploaded through form, have them placed in directory unique name, , store location of each image, actual path, on database.
then, can loop through , need do.
if want, post code have project did this, ask if want it.
it work if you're using mysql server tho; code written in php.
Comments
Post a Comment