0

I have a simple form with input

It works nice but I also want to add file to be uploaded by copying it and paste into browser using CTRL+V. How to do it?

Regards

SheppardPL
  • 85
  • 4
  • 12
  • 2
    Possible duplicate of [How can I let users upload files by copy/paste?](https://stackoverflow.com/questions/8468307/how-can-i-let-users-upload-files-by-copy-paste) – Charlie Aug 17 '17 at 06:47
  • @prasad I copied files but event.clipboardData.files is an empty array – SheppardPL Aug 17 '17 at 07:13
  • It is answered here: https://stackoverflow.com/questions/6333814/how-does-the-paste-image-from-clipboard-functionality-work-in-gmail-and-google-c You can use copy&paste for images and drag&drop for other files. – Nux Apr 05 '21 at 19:16

1 Answers1

1

You cannot directly access the file system unless the user specify the file explicitly. Copy and paste doesn't fall in to this category.

You can use latest html5 drag and drop and create a drop zone to upload files.

Please see this answer for other external options.

Charlie
  • 22,886
  • 11
  • 59
  • 90
  • I do not want to upload file but read its source only from clipboard – SheppardPL Aug 17 '17 at 07:23
  • Javascript cannot read file system content by the path. But it can by the user action - that is when the user selects the file and say "here it is". You are good to go with HTML5 fileReader API if that happens. Copying and pasting doesn't guarantee that level of security. – Charlie Aug 17 '17 at 09:15