# How to Load a local KML from browser url ?

**URL:** https://community.cesium.com/t/how-to-load-a-local-kml-from-browser-url/3183
**Category:** CesiumJS
**Created:** [October 14, 2015, 12:46pm UTC](https://community.cesium.com/t/how-to-load-a-local-kml-from-browser-url/3183 "2015-10-14T12:46:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Roberto\_Angeletti](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Roberto\_Angeletti](https://community.cesium.com/u/Roberto_Angeletti)
#### Post date: [October 14, 2015, 12:46pm UTC](https://community.cesium.com/t/how-to-load-a-local-kml-from-browser-url/3183/1 "2015-10-14T12:46:16Z")

</div>

Hello,

I am modifiying my QGIS GEarthView plugin, calling Cesium, (together) instead of GoogleEarth.

Now, my question is: how is the correct syntax to load a KML, from the browser URL (that is, without an html page) ?

I noticed that Dragging (& Dropping) the KML file on the CesiumVIewer web page, it works, but with:

[http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/index.html?source=file:///c:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml\_Lines.kml](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/index.html?source=file:///c:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml_Lines.kml)

it answers an error:

An error occurred while loading the file: file:///c:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml\_Lines.kml  
An error occurred while loading the file, which may indicate that it is invalid. A detailed error report is below:

NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml\_Lines.kml'.  
Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/rrr/.qgis2/python/plugins/gearthview/temp/GEKml\_Lines.kml'.  
&nbsp;&nbsp;&nbsp;&nbsp;at Error (native)  
&nbsp;&nbsp;&nbsp;&nbsp;at Function.u.load ([http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:29100](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:29100))  
&nbsp;&nbsp;&nbsp;&nbsp;at [http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:28401](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:28401)  
&nbsp;&nbsp;&nbsp;&nbsp;at Object.then ([http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:23643](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:23643))  
&nbsp;&nbsp;&nbsp;&nbsp;at e ([http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:23356](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:23356))  
&nbsp;&nbsp;&nbsp;&nbsp;at u ([http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:28356](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:418:28356))  
&nbsp;&nbsp;&nbsp;&nbsp;at t ([http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:424:17323](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:424:17323))  
&nbsp;&nbsp;&nbsp;&nbsp;at ui.load ([http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:426:2784](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:426:2784))  
&nbsp;&nbsp;&nbsp;&nbsp;at Function.ui.load ([http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:426:2290](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:426:2290))  
&nbsp;&nbsp;&nbsp;&nbsp;at [http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:466:17690](http://cesiumjs.org/Cesium/Build/Apps/CesiumViewer/CesiumViewerStartup.js:466:17690)

Surely you have already dealt with this issue, you can you please send me a link about it?

Thank you

Roberto

---

<div class="post-metadata">

### Author: ![Matt\_Amato](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/matt_amato/32/1993_2.png) [@Matt\_Amato](https://community.cesium.com/u/Matt_Amato)
#### Post date: [October 14, 2015, 1:22pm UTC](https://community.cesium.com/t/how-to-load-a-local-kml-from-browser-url/3183/2 "2015-10-14T13:22:44Z")

</div>

In most use cases, what you want to do isn’t possible. For security reasons, browsers are heavily sandboxed and reading a file uri directly from disk is impossible without having the browser bringing up a file selection dialog itself for the user to choose which file to read.

That being said, there is one way to do what you want. You need to read the contents of the file you want to pass to the browser and convert it to a [data uris](https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs) You can then pass the data uri as part of the URL the same way you pass normal urls. The one caveat here is that if the file you are loading hasother file url references in it, those won’t be readable either. For that you can either make them embedded data uris as well or in the case of a kml file, you can use a kmz instead.

If you are using an embedded browser control rather than just popping up an external browser, then you might have other options, but that depends on the control being used.

Hope that helps,

Matt

---

<div class="post-metadata">

### Author: ![Roberto\_Angeletti](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Roberto\_Angeletti](https://community.cesium.com/u/Roberto_Angeletti)
#### Post date: [October 14, 2015, 2:26pm UTC](https://community.cesium.com/t/how-to-load-a-local-kml-from-browser-url/3183/3 "2015-10-14T14:26:24Z")

</div>

> In most use cases, what you want to do isn't possible. For security  
> reasons, browsers are heavily sandboxed and reading a file uri directly  
> from disk is impossible without having the browser bringing up a file  
> selection dialog itself for the user to choose which file to read.

OK. But, I do not understand why the same problem do not happens with the  
drag & drop of the KML file.

> That being said, there is one way to do what you want. You need to read  
> the contents of the file you want to pass to the browser and convert it to  
> a data uris \<[https://developer.mozilla.org/en-US/docs/Web/HTTP/data\_URIs&gt](https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs&gt);  
> You can then pass the data uri as part of the URL the same way you pass  
> normal urls. The one caveat here is that if the file you are loading  
> hasother file url references in it, those won't be readable either. For  
> that you can either make them embedded data uris as well or in the case of  
> a kml file, you can use a kmz instead.

MMmmm. It seems complex.

I have to go to Cesium a KML file created by my plugin for QGIS. Which  
method do you suggest?

I can call a page of Cesium viewer that already includes' a KML, then I'm  
going to rewrite dynamically?
