Select to view content in your preferred language

Upload KML file to portal

7584
8
01-05-2015 01:07 AM
PramodHarithsa1
Frequent Contributor

Hi All,

I am trying to upload a KML file to portal using the AddItem rest service.

I have tried to replicate things from the upload shape file example Add shapefile | ArcGIS API for JavaScript

my code looks like,

var formId=dom.byId("KMLFile");
var item={
'type':'KML',
'title':'MyKMLFile',
'f':'json',
'callback.html':'textarea'
{;
var requestHandle=esri.request({
url:"https://domain.com/portal/sharing/rest/content/users/username/addItem",
handleAs:"json",
content:"item",
form:formId,
load:this.success,
error:this.failure
});

I get a success message and itemID but the file is not getting uploaded. Please let me know if I am missing something. Thanks.

Pramod

Tags (3)
8 Replies
larryzhang
Frequent Contributor

How do you use the KML in Portal?

It looks that you just upload and share KML via the poratl.  Is it correct?

If so, have you verified your KML file via the Add Item button on the My Content page, before coding?

You can also add the KML by referencing the  URL of a .kml or .kmz file as an item from the web to test if your KML works with your portal.

pls update us.

0 Kudos
PramodHarithsa1
Frequent Contributor

As I mentioned in my other post KML works fine when I try with the usual upload option.

The idea here is to upload the KML to portal and generate the URL so that the same can be shared across.

As KML can be added to the map only through a web server, we are using the item URL's to add them to the map.

Any hint on the code to upload them to portal?

0 Kudos
larryzhang
Frequent Contributor

On your description here, it looks that you plan to share the layer via KML, rather than 'Add KML and then share'...

If so, please refer to KML | ArcGIS API for JavaScript

KML_layer.PNG

0 Kudos
PramodHarithsa1
Frequent Contributor

For this to work I would need to host the KML/KMZ file on a webserver and then use.

In my case I have the files in my local machine, so I would like to upload them to the portal content and then use them.

The issue is I am unable to upload them to the portal content via code (which otherwise works if I use the portal Add Items option)

larryzhang
Frequent Contributor

Via JavaScript codes, to upload files like KML to the web, pls refer to http://blog.teamtreehouse.com/uploading-files-ajax
.

++++++++++++++

As you know, ESRI alredy offers many easy ways (ArcGIS Online, ArcGIS Explorer…) to upload KML files to ArcGIS Online or Portal for sharing.

PramodHarithsa1
Frequent Contributor

Thanks larry for the reply.

I am aware of the file upload option with ajax.

I was just trying to work with the portal rest api to do the same. (which should be very much possible)

Any hints on how to upload kml file using the addItem rest api: ArcGIS REST API
I have tried something like this: How to add item to the ArcGIS Portal with the portal API? - Geographic Information Systems Stack Exc... but have found no luck in getting the file on portal. (although the item gets added with size 0 )

Thanks,

Pramod

0 Kudos
PramodHarithsa1
Frequent Contributor

larry zhang

Yes it is just to upload and share. I have verified the KML file via the Add Item button. It works fine there.

I have also verified via the link I am trying to use: https://domain.com/portal/sharing/rest/content/users/username/addItem

everything works except thro' the code!

0 Kudos
HumzaAkhtar
Deactivated User

Dear Pramod,

I am also having a similar issue while uploading JSON files to my arcgisonline account. Did you figure out the issue ?

0 Kudos