Select to view content in your preferred language

10.1 Upload functionality

2354
3
Jump to solution
12-20-2012 10:49 AM
BrianLeroux
Frequent Contributor
I am trying to utilize the new functionality in 10.1 that allows you to upload a file as part of a geoprocessing task. Does anytone have any examples on how to upload a file using C#. I have been hacking around with and and can't get it to work.

Thanks..
0 Kudos
1 Solution

Accepted Solutions
BrianLeroux
Frequent Contributor
Well this turned out much easier.
private void NewAdd_Click(object sender, RoutedEventArgs e)         {             var uploadTask = new ESRI.ArcGIS.Client.Tasks.UploadTask("http://myserver/arcgis/rest/services/GPTools/WildfireUpload/GPServer/uploads/upload");             uploadTask.UploadCompleted += UploadTask_Complete;             uploadTask.Failed += UploadTask_Failed;              uploadTask.UploadAsync(new UploadParameters() { FileStream = fileStream, FileName = strFile });          }          private void UploadTask_Complete(object sender, UploadEventArgs e)         {             Geoprocessor geoprocessorTask = new Geoprocessor("http://gis/arcgis/rest/services/GPTools/WildfireUpload/GPServer/ZipImportTest");             geoprocessorTask.ExecuteCompleted += GeoprocessorTask_ExecuteCompleted;             geoprocessorTask.Failed += GeoprocessorTask_Failed;              List<GPParameter> parameters = new List<GPParameter>();              parameters.Add(new GPItemID("Input_File", e.Result.Item.ItemID));              geoprocessorTask.ExecuteAsync(parameters);         }

View solution in original post

0 Kudos
3 Replies
BrianLeroux
Frequent Contributor
I am close to getting this using RestSharp but I am stuck with an NTLM authentication issue. I get a 401 for a response and notice in fiddler there is no authentication header. Any ideas?
string strdescr = "WillowTestfromSL";
            string strRespFormat = "pjson";
            RestRequest request = new RestRequest("http://myserver/arcgis/rest/services/GPTools/WildfireUpload/GPServer/uploads/upload", Method.POST);

            //Get the file stream
            byte[] bytes = null;
            BinaryReader br = new BinaryReader(fileStream);
            bytes = br.ReadBytes((int)numBytes);
                             
            //add parameters
            request.AddFile("file", bytes,strFile,"application/x-zip-compressed");
            request.AddParameter("desription", strdescr);
            request.AddParameter("f", strRespFormat);
            
            //calling server with restClient 
            RestClient restClient = new RestClient();
            restClient.ExecuteAsync(request, (response) => 
            {  
                if (response.StatusCode == HttpStatusCode.OK)  
                {  
                    //upload successfull  
                    MessageBox.Show("Upload completed succesfully...\n" + response.Content);  
                }  
                else 
                {  
                    //error ocured during upload  
                    MessageBox.Show(response.StatusCode + "\n" + response.StatusDescription);  
                }  
            }); 
0 Kudos
BrianLeroux
Frequent Contributor
I was able to get the code below to work by setting my request to null when finished. However, I ran into another issue with trying to get the response from the successful upload. I get a message stating my cookie is exceeding the limit of 4096. Is there a way to change the cookie limit? I am using NTLM for single sign on authentication.
0 Kudos
BrianLeroux
Frequent Contributor
Well this turned out much easier.
private void NewAdd_Click(object sender, RoutedEventArgs e)         {             var uploadTask = new ESRI.ArcGIS.Client.Tasks.UploadTask("http://myserver/arcgis/rest/services/GPTools/WildfireUpload/GPServer/uploads/upload");             uploadTask.UploadCompleted += UploadTask_Complete;             uploadTask.Failed += UploadTask_Failed;              uploadTask.UploadAsync(new UploadParameters() { FileStream = fileStream, FileName = strFile });          }          private void UploadTask_Complete(object sender, UploadEventArgs e)         {             Geoprocessor geoprocessorTask = new Geoprocessor("http://gis/arcgis/rest/services/GPTools/WildfireUpload/GPServer/ZipImportTest");             geoprocessorTask.ExecuteCompleted += GeoprocessorTask_ExecuteCompleted;             geoprocessorTask.Failed += GeoprocessorTask_Failed;              List<GPParameter> parameters = new List<GPParameter>();              parameters.Add(new GPItemID("Input_File", e.Result.Item.ItemID));              geoprocessorTask.ExecuteAsync(parameters);         }
0 Kudos