Answered by:
How to access to the image data as a HTML file object

Question
-
User264732274 posted
see the code
window.onload = function() { document.getElementById("pasteTarget"). addEventListener("paste", handlePaste); };
function handlePaste(e) { for (var i = 0 ; i < e.clipboardData.items.length ; i++) { var item = e.clipboardData.items[i]; console.log("Item: " + item.type); if (item.type.indexOf("image -1) { uploadFile(item.getAsFile()); } else { console.log("Discardingimage paste data"); } } }
i guess the above code will not work in all browser. so just tell me what to change as a result it should work in all browser, event in those browser which does not support HTML5 file object. looking for suggestion and rectified code. thanks
Tuesday, February 2, 2016 7:23 PM
Answers
-
User-474980206 posted
currently only chrome and firefox allow access to a clipboard image. for other browser you will need to code a plugin or might be able to code one in flash (flash should do the upload).
most current browsers will support a drop of filename for upload. for this you should use one of the libraries will flash support for browsers that do not use the api.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 2, 2016 8:36 PM -
User61956409 posted
Hi sudip_inn,
According to your code, it seems that you’d like to paste Image from Clipboard using JavaScript. I agree with bruce , as far as I know only Google Chrome and Safari support the latest clipboard APIs. And FileReader object is not supported in all browsers.
https://developer.mozilla.org/en/docs/Web/API/FileReader
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, February 3, 2016 7:30 AM -
User-474980206 posted
To write a browser plugin, go to each browsers developers site and get the documentation. It different for every browser and o/s. Generally you write the plugin in c, but for safari you can use objective/c or swift.
To write the plugin in flash, you buy the flash developers kit from Adobe. There are file upload libraries in flash, Google for them, but because browser support for flash is dropping, they are not as common as they used to be. But it should work as a polyfil for old browsers.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 4, 2016 3:23 PM
All replies
-
User-474980206 posted
currently only chrome and firefox allow access to a clipboard image. for other browser you will need to code a plugin or might be able to code one in flash (flash should do the upload).
most current browsers will support a drop of filename for upload. for this you should use one of the libraries will flash support for browsers that do not use the api.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, February 2, 2016 8:36 PM -
User61956409 posted
Hi sudip_inn,
According to your code, it seems that you’d like to paste Image from Clipboard using JavaScript. I agree with bruce , as far as I know only Google Chrome and Safari support the latest clipboard APIs. And FileReader object is not supported in all browsers.
https://developer.mozilla.org/en/docs/Web/API/FileReader
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, February 3, 2016 7:30 AM -
User264732274 posted
thanks for reply. u said "for this you should use one of the libraries will flash support for browsers that do not use the api."
so give me any js or jquery lib or plug-in name which will have some fallback mechanism for old browser. looking for help.
Wednesday, February 3, 2016 8:50 AM -
User264732274 posted
so give me any js or jquery lib or plug-in name which will have some fallback mechanism for old browser. plugin must have some tutorial which help me to implement this.
Wednesday, February 3, 2016 8:50 AM -
User-474980206 posted
To write a browser plugin, go to each browsers developers site and get the documentation. It different for every browser and o/s. Generally you write the plugin in c, but for safari you can use objective/c or swift.
To write the plugin in flash, you buy the flash developers kit from Adobe. There are file upload libraries in flash, Google for them, but because browser support for flash is dropping, they are not as common as they used to be. But it should work as a polyfil for old browsers.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 4, 2016 3:23 PM