- Home /
Application.OpenURL not working with Data URI
If you enter the following URI in the browser:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
it will show a 5x5 pixels red circle.
I'm trying to do this inside Unity with Application.OpenURL
or Application.ExternalEval("window.open(url,'_blank')")
but it does nothing. It doesn't work on editor nor on Mac build, but strangely it works on the Web Player (and that's why I think my code is working).
Application.ExternalEval is only available in the webplayer.. Have you tried using this for your standalone build?
Application.OpenURL("data:image/png;base64,iVBORw0$$anonymous$$GgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIB$$anonymous$$E0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==");
yes, you are right. But I tried using OpenURL, the result is the same (I wrote this in the question).
Application.OpenURL should work, to test what is going wrong try testing some of these and see if it will open a browser window:
Application.OpenURL("http://answers.unity3d.com/index.html");
and if that works then you can try the following (note that it has the url address as a string rather than a variable):
Application.OpenURL("data:image/png;base64,iVBORw0$$anonymous$$GgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIB$$anonymous$$E0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==");
Let us know if the first code snippet works - it should since it is just a normal url.
I did it, it open regular URLs and don't open when the URI is a string.
Thank you very much for this. I really don't know anything about web dev, so this will help a lot. Yet, OpenURL will accept URI when you use the web player, so maybe there is another answer on why it doesn't work on editor. But for my application, I'll stick with your solution.
Answer by ByteSheep · May 23, 2013 at 02:18 AM
Yeah I just tested it and it looks like the OpenURL function will only allow the http: and https: protocols.
This makes what you are trying to do a bit more complicated.. You could use OpenURL to open a php page and pass the image info as a GET variable. Then the php page could open the image for you. So it might look something like:
var open_url = "http://yourdomain.com/open_image.php";
open_url += "?imageinfo=" + ImageBytes; //add your image byte array
Application.OpenURL(open_url);
Then the php file could look like this:
<?php
if(isset($_GET['imageinfo']))
{
$image_info = $_GET['imageinfo'];
$data_URI = "data:image/png;base64,";
echo "<meta http-equiv='refresh' content='0;url=".$data_URI."".$image_info."'>";
}
?>
Here's an example project using this method.
Note that the server the php page is hosted on is currently really slow, so it takes a few seconds before it redirects to the actual image.. With a proper server on a normal webpage the load time should normally be under a second.