Can I assume that Mac OS X clipboard image data is png?
When I try to MIME-detect the clipboard data, it returns application/octet
.
This has the undesirable effect of causing every browser to download the image rather than display it.
If I force the content-type to image/png, everything seems fine, but I wondered if there is a way for me to not have to make the assumption?
$log.debug(e.originalEvent.clipboardData);
for (var i = 0; i < e.originalEvent.clipboardData.items.length; i++) {
var item = e.originalEvent.clipboardData.items[i];
$log.info("Item type: " ,item);
if (item.type.indexOf("image") != -1) {
$scope.token.images = [];
$log.debug(item.getAsFile(), {});
...
I use https://github.com/broofa/node-mime to detect MIME types.
In the Connections pane, go to the site, application, or directory for which you want to add a MIME type. In the Home pane, double-click MIME Types. In the MIME Types pane, click Add... in the Actions pane. In the Add MIME Type dialog box, add the file name extension and MIME type, and then click OK.
At least in theory, no, you can't assume that.
Here is what apple says: "To get a list of types currently available on the clipboard, you can use the types property of the clipboardData object. This property contains an array of strings with the MIME types of the available data." Webkit DOM Programming Topics
At least according to w3c the options are:
edit:
The reason the MIME-detect returns application/octet
is that the library you are using falls back to that when it doesn't know the type as you can see in this line of the test.js file:
assert.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
This answer explains in more detail how to deal with this "arbitrary binary data."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With