Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular paste picture from clipboard

I'm trying to create a functionality where users can paste a picture on the page son I can upload it to the server and show it to he user.

I'm aware of the paste event, and tried to implement from there but haven't been able to access any data from the clipboard from the event, either the files or items array from the clipboard field of the event are always empty when I press ctrl + v.

here's the code:

    <div (paste)="pastePicture($event)" style="height: 300px; width: 300px; background-color:#ccc;">
</div>

  pastePicture(event: ClipboardEvent) {
console.log(event);  }

https://plnkr.co/edit/QmELBtWJqjAuEwGPiCZh?p=preview

Any thoughts on this?

like image 947
dazzed Avatar asked Nov 06 '17 11:11

dazzed


1 Answers

You can get all data from the event using property event.clipboardData. For example, to get text data you can call: event.clipboardData.getData('text'). Also you can find properties: files, items and types which would help you to get more content.

like image 131
Maxim Goncharuk Avatar answered Nov 15 '22 00:11

Maxim Goncharuk