ESRI Javascript API import Shapefile

3192
11
05-07-2020 05:01 AM
deleted-user-VQ40NmU7Vt6N
New Contributor II

Hello everyone

I am making an application using ArcGIS API for JavaScript 4.15.


I would like to be able to have a button by which to upload my shapefile files from my local to my ArcGIS for Developers account, so I can use them later.

I would like doing this using javascript code, but I have not found a example of this.

Thanks!!!

11 Replies
RobertScheitlin__GISP
MVP Emeritus

Sorry I do not have a step by step for you.

0 Kudos
deleted-user-VQ40NmU7Vt6N
New Contributor II

So, the function should be something like this:

// user is a portalUser.
// fileList is an array of files.
// tags is an array of strings
userid=Subscription ID (the only ID i have from https://igarcia27.maps.arcgis.com/home/organization.html#overview )
file="C:\Users\igarcia\Downloads\myshapefile.zip"
server token= Temporary access token (the only token i have in ArcGIS for Developers )
function addFileaAsPortalItem(tags){
  const file = file;
  let form = new FormData();
  form.append('file',file);
  form.append("f", "json");
  form.append("title", "myshapefile");
  form.append("name", "myshapefile");
  form.append("type",'shapefile');
  form.append("token", <server token>);
  form.append("filename", "myshapefile");
  form.append("tags", tags.join());

  return esriRequest('https://www.arcgis.com/sharing/rest/content/users/'+userid+'/addItem',{
    method: 'post',
    query: form
  });
}
This does not work, likely because several things are wrong.
sorry for my insistence but I have no idea how to do it
Thanks!
0 Kudos