Survey123: How to download images from survey - C#

754
9
05-12-2017 07:13 AM
Highlighted
New Contributor II

So, does anyone know where to find the documentation on how to download the images, which are attached to a survey?  I have been using the API Rest Service to do everything else for my C# application and I assume this might be the same.  I will be saving the images to a SQL Server DB.  Any assistance would be greatly appreciated.

Thank you,
Bill B

Reply
0 Kudos
9 Replies
Highlighted
New Contributor II

This is done via the queryAttachments() method of the FeatureService in the API Rest Service.

Reply
0 Kudos
Highlighted
New Contributor II

Okay, so I was incorrect.  QueryAttachments() only brings back the data pertaining to the images (length, datatype, name, etc.).  I did also find that using ...FeatureServer/0/17/attachments/3?token=...., I can actually view the image.  Not what I want though.  I need to be able to bring the image back at least in a byte [].  I am doing this in C# .net.  Help, Anyone???

Reply
0 Kudos
Highlighted
New Contributor II

I think I figured it out.  By setting the parameter f = json, I was able to use WebClient.DownloadData("url") into a byte[].  I still have further testing to do.

Reply
0 Kudos
Highlighted
New Contributor II

Are you still working on this issue? I imagine you are doing something similar to what I am working on. I was able to get the images from Survey123 int a byte[] by doing the following.

var response = wb.UploadValues(ServiceUrl + "query", "POST", request);
byte[] vs = response;

Reply
0 Kudos
Highlighted
New Contributor II

Hi Craig,

   I was able to figure this out after I started going through the "response" and looking for the data I needed.  Each of the surveys could have multiple images attached.  So, I needed to iterate through the Json response of a "queryattachments" request based on a Survey "Id" and then do an "attachments" request based on the "objectid" associated with each image.  Thank you for replying.  It's good to know someone else is out there working on the same thing.

Bill

Highlighted
New Contributor II

Bill,

How were you able to setup the Survey feature layer for queryAttachements? I can't seem to locate where I turn that on. I am using version 10.51 

Reply
0 Kudos
Highlighted
New Contributor II

Craig,

   I am a little confused on what you are asking.  Are you talking about adding an image control to the xls form for a survey?

Bill

Reply
0 Kudos
Highlighted
New Contributor II

Bill,

   I don't seem to have the option to use queryAttachments and can only use the query (Which works fine for the data in the table just not the attachments). I didn't know if there was a setting you used to set this up for the feature class. It's possible I am using the query incorrect but I followed the documentation. 

This is the query that is after my service_"ID IS HERE"  "/FeatureServer/0/queryAttachments?objectIds=50&globalIds=&definitionExpression=&attachmentTypes=&resultOffset=&resultRecordCount="

This is the result.

Reply
0 Kudos
Highlighted
New Contributor II

Hi Craig,

   I totally understand the frustration.  Documentation is very limited.  I "stumbled" across a good majority of the solutions. It would be easier to talk with you than message back and forth.  If you have a chance you can call me at 402-471-3991.  I may be leaving early today because we have an icey/snowy forecast today, but please leave me a number to call if I am not here.  I am sure I can get you going in the right direction.

Bill

Reply
0 Kudos