How to attach an image to runtime geodatabase?

4292
9
02-03-2017 02:57 AM
BonyRaju
New Contributor
 We are unable to attach an image file to the geodatabase on ArcGIS Runtime SDK for .NET v100(Xamarin). I am sending the code we have worked.
 
FeatureQueryResult qfr = await gft.QueryFeaturesAsync(queryParams);
            Feature onerecord = qfr.FirstOrDefault();
           
            ArcGISFeature a = onerecord as ArcGISFeature;
            if (a.CanEditAttachments)
            {
                Debug.WriteLine("true");
            }
            Byte[] b1;
            using (var memoryStream = new MemoryStream())
            {
                file.GetStream().CopyTo(memoryStream);
                file.Dispose();
                b1 = memoryStream.ToArray();
            }
           
           await a.AddAttachmentAsync(filename, @"image/", b1);
Please see the attached image for the details
0 Kudos
9 Replies
AnttiKajanus1
Occasional Contributor III

I think that your feature service doesn't support editing. Can you verify that the debug message is written and the feature and the FeatureTable has correct values indicating that the edit can be done.

var featureTable = new ServiceFeatureTable(new Uri(url));
await featureTable.LoadAsync();

if (!featureTable.IsEditable || !featureTable.HasAttachments)
    throw new Exception("Editing attachments not supported");
var query = await featureTable.QueryFeaturesAsync(new QueryParameters() { WhereClause = "1=1" });
var feature = query.First() as ArcGISFeature;
if (!feature.CanEditAttachments)
    throw new Exception("Cannot edit attachment on this feature");
var fileBytes = File.ReadAllBytes(@"C:\Temp\P1050951.JPG");
var attachment = await feature.AddAttachmentAsync("test.jpg", @"image/", fileBytes);
0 Kudos
BonyRaju
New Contributor

Hi Antti, thank you for the comment

Feature service attachment enabled and editable but the debug message is giving value false.Why is it so? How to make the feature editable? I am working with Arcgis runtime SDK for Xamarin

0 Kudos
AnttiKajanus1
Occasional Contributor III

You might need to load the feature to get the information loaded to it before using the feature.

var feature = query.First() as ArcGISFeature;
await feature.LoadAsync(); // load feature to get the metadata
if (!feature.CanEditAttachments)
    throw new Exception("Cannot edit attachment on this feature");
...more stuff
0 Kudos
BonyRaju
New Contributor

We tried your LoadAsync code. 'CanEditAttachments' returns false. How to enable it? 

Thank you

0 Kudos
AnttiKajanus1
Occasional Contributor III

Here is a doc to hosted services.

Can you have a look into your service and make sure that the your service has `HasAttachements` set to true and you can see `AddAttachement` rest endpoint in the service. You can access the later by investigating existing feature in the service.

Here is a example how to access the feature endpoint

Rest endpoint for feature 5802

Are you using hosted feature services or are they published through ArcGIS Server?

0 Kudos
BonyRaju
New Contributor

HasAttachment is set to true and also able to fetch attached image from feature service from ArcGIS online. We are using hosted feature service. 

How can we enable CanEditAttachments?

0 Kudos
AnttiKajanus1
Occasional Contributor III

Can you share your service definition in whole? You can send it to my mail akajanus@esri.com.

0 Kudos
BonyRaju
New Contributor

Please check the mail

0 Kudos
PhilipThompson11
New Contributor II

Did you identify why CanEditAttachments was returning false to you?

0 Kudos