Select to view content in your preferred language

Add file to My Content (Add item) to AGOL

318
0
06-29-2023 07:39 AM
RejeanLabbe
New Contributor III

I would like to add a file (an image in my case) to My content on AGOL.

In the ArcGISOnlineConnect project from ArcGIS Pro SDK Community Samples, we can run queries with Rest API.

We can get an item with this call :

"/sharing/content/items/{0}?f=pjson;Item;<Enter an ArcGIS Online Item Id>"

 

The code goes like that :

private void CmdDoQuery()
        {
            try
            {
                var httpEsri = new EsriHttpClient() { BaseAddress = ArcGISPortalManager.Current.GetActivePortal().PortalUri };
                // value has the following format: url with {};Redlands,...,...;Search Query,...,...
                // where Redlands ... are values and search query are keys
                var parts = AgolQuery.Value.Split(";".ToCharArray());
                var getUrl = parts[0];

                // get parameters
                if (CallParams.Count > 0)
                {
                    var lstParams = new List<object>() as IList<object>;
                    foreach (var kv in CallParams)
                        lstParams.Add(kv.Param);
                    getUrl = string.Format(parts[0], lstParams.ToArray());
                }
                System.Diagnostics.Debug.WriteLine(getUrl);
                var httpResponse = httpEsri.Get(getUrl);
                if (httpResponse.StatusCode == HttpStatusCode.OK && httpResponse.Content != null)
                {
                    var content = httpResponse.Content.ReadAsStringAsync().Result;
                    QueryResult = string.Format(@"{0}{1}", getUrl, System.Environment.NewLine);
                    QueryResult += string.Format(@"IsSuccessStatusCode: {0}{1}", httpResponse.IsSuccessStatusCode, System.Environment.NewLine);
                    QueryResult += string.Format(@"StatusCode: {0}{1}", httpResponse.StatusCode, System.Environment.NewLine);
                    QueryResult += content;
                    if (AgolQuery.Key == ArcGISOnlineQueries.AGSQueryType.GetSelf)
                    {
                        _AgolUser = AgolUser.LoadAgolUser(content);
                    }
                    else if (AgolQuery.Key == ArcGISOnlineQueries.AGSQueryType.GetSearch)
                    {
                        _AgolSearchResult = AgolSearchResult.LoadAgolSearchResult(content);
                    }
                    else if (AgolQuery.Key == ArcGISOnlineQueries.AGSQueryType.GetUserContent)
                    {
                        _AgolUserContent = AgolUserContent.LoadAgolUserContent(content);
                        _AgolFolderContent = null;
                    }
                    else if (AgolQuery.Key == ArcGISOnlineQueries.AGSQueryType.GetUserContentForFolder)
                    {
                        _AgolFolderContent = AgolFolderContent.LoadAgolFolderContent(content);
                    }
                    System.Diagnostics.Debug.WriteLine(QueryResult);
                }
            }
            catch (Exception ex)
            {
                QueryResult = ex.ToString();
            }
        }

 

I assume there is and additem end point that allow us to send a file and retrieve the new created id.

Any help would be apprecieated.

Thanks

0 Kudos
0 Replies