REST API Upload Operation

2925
3
Jump to solution
10-22-2012 12:15 PM
ToddSmith4
New Contributor II
After looking at the resources page - I'm looking for a basic example of how to upload a raster to my image service.  I'm able to do this fine through the generic web GUI (http://<service-uploads-url>/upload), but I'm looking to do this dynamically in my custom javascript web app. 

I figure there is a simple REST URL that I can construct.  However, I don't see any parameter where I can define the source location of my raster that is to be uploaded to the server.
0 Kudos
1 Solution

Accepted Solutions
ToddSmith4
New Contributor II
Just an update.  I did get the Upload and Add Raster operators working with the ArcGIS Server 10.1 REST API.  On the server I have an Image Mosiac dataset exposed as an Image Service.  I'm using STK Server to generate a custom raster for me in .jp2 format.  The raster is saved to a temp directory on the server, and then I invoke the Upload then Add Raster operators which then publishes the raster to the server and makes it immediately available through the Image Service.  It works great! 

Here is a snippet that does the Add Raster operation:
        public string AddRasterToArcGISServer(string ArcGISImageServerURL, string RasterItemID)         {             Uri address = new Uri(ArcGISImageServerURL + "/add");              // Create the web request               HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;              // Set type to POST               request.Method = "POST";             request.ContentType = "application/x-www-form-urlencoded";              // Create the data we want to send               string itemIds = RasterItemID;             string rasterType = "Raster Dataset";              StringBuilder data = new StringBuilder();             data.Append("itemIds=" + HttpUtility.UrlEncode(itemIds));             data.Append("&rasterType=" + HttpUtility.UrlEncode(rasterType));              // Create a byte array of the data we want to send               byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());              // Set the content length in the request headers               request.ContentLength = byteData.Length;              // Write data               using (Stream postStream = request.GetRequestStream())             {                 postStream.Write(byteData, 0, byteData.Length);             }              string functionResponse = "";              // Get response               using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)             {                 // Get the response stream                   StreamReader reader = new StreamReader(response.GetResponseStream());                  // Console application output                   functionResponse = reader.ReadToEnd();             }               return functionResponse;         }

View solution in original post

0 Kudos
3 Replies
PeterBecker
Esri Regular Contributor
See   http://resources.arcgis.com/en/help/rest/apiref/isadd.html
The location where the raters get stored on the server are defined as part of the Image Service properties.
0 Kudos
ToddSmith4
New Contributor II
Thanks!  Ok - so the basic workflow is to manually copy the raster somewhere to the server (the registered directory) and then run the add raster operation to add it to the Image Service?

I will try that out and let you know how I make out.  I'm just looking for the basic workflow to make sure I'm using the 10.1 capabilities appropriately.
0 Kudos
ToddSmith4
New Contributor II
Just an update.  I did get the Upload and Add Raster operators working with the ArcGIS Server 10.1 REST API.  On the server I have an Image Mosiac dataset exposed as an Image Service.  I'm using STK Server to generate a custom raster for me in .jp2 format.  The raster is saved to a temp directory on the server, and then I invoke the Upload then Add Raster operators which then publishes the raster to the server and makes it immediately available through the Image Service.  It works great! 

Here is a snippet that does the Add Raster operation:
        public string AddRasterToArcGISServer(string ArcGISImageServerURL, string RasterItemID)         {             Uri address = new Uri(ArcGISImageServerURL + "/add");              // Create the web request               HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;              // Set type to POST               request.Method = "POST";             request.ContentType = "application/x-www-form-urlencoded";              // Create the data we want to send               string itemIds = RasterItemID;             string rasterType = "Raster Dataset";              StringBuilder data = new StringBuilder();             data.Append("itemIds=" + HttpUtility.UrlEncode(itemIds));             data.Append("&rasterType=" + HttpUtility.UrlEncode(rasterType));              // Create a byte array of the data we want to send               byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());              // Set the content length in the request headers               request.ContentLength = byteData.Length;              // Write data               using (Stream postStream = request.GetRequestStream())             {                 postStream.Write(byteData, 0, byteData.Length);             }              string functionResponse = "";              // Get response               using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)             {                 // Get the response stream                   StreamReader reader = new StreamReader(response.GetResponseStream());                  // Console application output                   functionResponse = reader.ReadToEnd();             }               return functionResponse;         }
0 Kudos