private async Task <string> UploadImpl() { // Create EsriHttpClient object var httpClient = new EsriHttpClient(); // Upload vtpk file to the currently active portal var itemToUpload = ItemFactory.Instance.Create(FilePath); var tags = new string[] { "ArcGIS Pro", "SDK", "UploadVtpkToAgol Demo" }; var portalUrl = ArcGISPortalManager.Current.GetActivePortal().PortalUri.ToString(); var uploadDefn = new UploadDefinition(portalUrl, itemToUpload, tags); var result = httpClient.Upload(uploadDefn); if (result.Item1 == false) { return($@"Unable to upload this item: {FilePath} to ArcGIS Online"); } // Once uploaded make another REST call to search for the uploaded data var portal = ArcGISPortalManager.Current.GetActivePortal(); string userName = ArcGISPortalManager.Current.GetActivePortal().GetSignOnUsername(); //Searching for Vector tile packages in the current user's content var pqp = PortalQueryParameters.CreateForItemsOfTypeWithOwner(PortalItemType.VectorTilePackage, userName, "tags: UploadVtpkToAgol Demo"); //Execute to return a result set PortalQueryResultSet <PortalItem> results = await ArcGISPortalExtensions.SearchForContentAsync(portal, pqp); if (results.Results.Count == 0) { return($@"Unable to find uploaded item with query: {pqp.Query}"); } // Create an item from the search results string itemId = results.Results[0].ID; var currentItem = ItemFactory.Instance.Create(itemId, ItemFactory.ItemType.PortalItem); var lyrParams = new LayerCreationParams(currentItem); // Finally add the feature service to the map // if we have an item that can be turned into a layer // add it to the map if (LayerFactory.Instance.CanCreateLayerFrom(currentItem)) { LayerFactory.Instance.CreateLayer <FeatureLayer>(lyrParams, MapView.Active.Map); } return($@"Uploaded this item: {results.Results[0].Name} [Type: {results.Results[0].Type}] to ArcGIS Online and added the item to the Map"); }
/// <summary> /// Uploads a local item to online with its parameters /// </summary> /// <param name="baseURI"></param> /// <param name="itemPathStr"></param> /// <param name="thumbnail"></param> /// <param name="tags"></param> /// <returns></returns> async Task <Tuple <bool, string> > UploadItemAsync(string baseURI, string itemPathStr, string thumbnail, string tags) { String[] tags_arr = tags.Split(new Char[] { ',', ':', '\t' }); EsriHttpClient myClient = new EsriHttpClient(); Tuple <bool, string> response = null; var itemToUpload = ItemFactory.Instance.Create(itemPathStr); if (itemToUpload != null) { //Create the upload defintion var uploadDfn = new UploadDefinition(baseURI, itemToUpload, tags_arr); uploadDfn.Thumbnail = thumbnail; //upload item response = myClient.Upload(uploadDfn); //response = myClient.Upload(baseURI, itemToUpload, thumbnail, tags_arr); //obsolete if (response.Item1) //Upload was successfull { //Search for the uploaded item to get its ID. Tuple <bool, PortalItem> result = await SearchPortalForItemsAsync(baseURI, itemToUpload); if (result.Item1) //search successful { ItemID = result.Item2.ToString(); return(new Tuple <bool, string>(true, result.Item2.ID)); } else //item not found { ItemID = "Cannot find item online"; return(new Tuple <bool, string>(true, "Cannot find item online")); } } else //Upload failed { ItemID = "Upload failed"; return(new Tuple <bool, String>(false, "Upload failed")); } } else //Item was not created { ItemID = "Item cannot be created"; return(new Tuple <bool, String>(false, "Item cannot be created")); } }