Perspective - Accessing images on the clipboard

I have a need where It would make the users life a lot easier if I could provide a way to paste the image data from the clipboard and get those image bytes. I could then store them off to db or file or send them out to a REST call for OCR.

I’ve been looking at the async clipboard API and have written an html file through Webdev that can put text into the clipboard. So i know the API is working just fine in Chrome. I just cannot figure out how to get the feature to return data.

I think I need to define a python file where I can setup the doGet and doPost events to handle the returned data. Does this sound right? Or is there another way to access the clipboard data without needing to use the webdev?

Sounds like a good candidate for an SDK add-on module (to make a Perspective component). That’s currently the only way to have non-IA defined javascript in the client browser.

I thought you could create javascript in a page that is created through webdev. Essentially, my thought is to have a very simple page that only has a button to get the image from the clipboard and show that page in an inline frame on the perspective view.

Is that not possible? If the you are writing the page (html) through the the webdev, won’t it execute on the client side?

You can execute custom JS in a webdev loaded page, but I suspect you’ll have problems “escaping” the sandbox of the iframe to actually do anything with that data in your primary Perspective session.

1 Like

Precisely. The Async Clipboard API permissions have to be included in the iframe tag for the inner page to have any access.

Yeah. I suppose I was thinking of storing the image and then looking for the file to appear in the DB. At that point I could do something with it.

That would be possible - you’ll probably have to do a separate POST in your JS inside the iframe, and have another Webdev endpoint that handles the upload. In theory you could also send a system.perspective.sendMessage() message from webdev after that happened, but bookkeeping the session IDs may be hard (or you could use system.perspective.getSessionInfo() to broadcast a message to all sessions).