Select to view content in your preferred language

addAttachment using RestSharp slow

574
0
02-27-2023 06:58 AM
ZachBray
Emerging Contributor

I am working on a asp.Net MVC Web App that reads a gps data and jpeg files from an online source and then uploads the data using the REST API addFeatures and addAttachment to our internal ArcGIS Enterprise.  I have been able to get this to work using the RestSharp reference and ExecuteAsync, however the addAttachment call is very slow compared to either rest services feature server endpoint or ArcGIS Pro.  Does anyone have an example or can offer suggestions to improved performance?

 

public async Task<string> addAttachment()
{
JObject jobject = new JObject();
string boundry = Guid.NewGuid().ToString();
var options = new RestClientOptions(BaseURL)
{
MaxTimeout = -1
};
var client = new RestClient(options);
var request = new RestRequest(String.Format("{0}/{1}/rest/services/SVEC/{2}/FeatureServer/{3}/{4}/addAttachment", BaseURL, ServerWebAdapter, FeatureService, LayerNumber.ToString(),ArcGISattachment.objectId.ToString()), Method.Post);
request.AddHeader("Content-Type", String.Format("multipart/form-data; boundary={0}",boundry));
request.AddQueryParameter("token", Token);
request.AddQueryParameter("f", "json");
request.AddParameter("f", "json");
//request.AddFile("attachment", , ArcGISattachment.fileName, String.Format("multipart/form-data; boundary={0}", boundry));
request.AddFile("attachment",ArcGISattachment.pathName, "image/jpeg");


RestResponse response = await client.ExecuteAsync(request);

jobject = (JObject)JsonConvert.DeserializeObject(response.Content);
if (jobject.ContainsKey("addAttachmentResult"))
{
ArcGISattachment.addAttachmentResult = new addAttachmentResult();
//ArcGISattachment.addAttachmentResult.globalId = jobject["addAttachmentResult"]["globalId"].ToString();
ArcGISattachment.addAttachmentResult.objectId = int.Parse(jobject["addAttachmentResult"]["objectId"].ToString());
ArcGISattachment.addAttachmentResult.success = (bool)jobject["addAttachmentResult"]["success"];
if (!(bool)jobject["addAttachmentResult"]["success"])
{
ArcGISattachment.addAttachmentResult.error = new addError();
ArcGISattachment.addAttachmentResult.error.code = jobject["addAttachmentResult"]["error"]["code"].ToString();
ArcGISattachment.addAttachmentResult.error.description = jobject["addAttachmentResult"]["error"]["description"].ToString();
}
}
request = null;
response = null;
client = null;
return ArcGISattachment.addAttachmentResult.objectId.ToString();
}

Thanks,

Zach

0 Replies