Attachments Issue

849
5
05-16-2017 12:05 PM
AndyWright
Occasional Contributor

I'm writing a Xamarin Forms app that contains a tool which allows the user to add attachments to a point feature class within a SQLite geodatabase generated from a syncable feature service.  If the user adds multiple attachments (i.e more than 5) between syncs back to the feature service the sync process fails with the following error:

Failed to sync geodatabase: Error in uploading item part icda5bb8a-3bd4-4d68-82c4-87d9eb277c7a

  at Esri.ArcGISRuntime.Http.ArcGISHttpClientHandler+ArcGISClientHandlerInternal+<SendAsync>d__13.MoveNext () [0x00825] in <687a544c38e8410dbac0acfc0843ba7e>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Net.Http.HttpClient+<SendAsyncWorker>c__async0.MoveNext () [0x000f3] in <33125f85abf045418d5a40b4ae0d9bb5>:0
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <8c304e4006094a46a7950338a3b3cb5d>:0
  at Esri.ArcGISRuntime.Internal.RequestRequiredHandler+<IssueRequestAndRespond>d__14.MoveNext () [0x005ae] in <687a544c38e8410dbac0acfc0843ba7e>:0

I am able to sync less than 5 attachments successfully however.  5 is not a hard and fast limit though, as I've seen it fail with 2 or 3 from time to time.  I've tested this on Windows, iOS, and Android devices against two different feature services and get the same error.  Is anyone aware of any bugs or limitations with respect to syncing data with associated attachments?  Are there any workarounds?

Thanks ...

0 Kudos
5 Replies
NagmaYasmin
Occasional Contributor III

Hi Andy,

I wasn't able to reproduce the issue at my side, i.e, I successfully synced more than 5 attachments with the below two services:

Layer: Damage to Commercial Buildings (ID: 0) 

Layer: Marine (ID: 0) 

I am using WPF version to test. If you still have the issue do you mind to try using the above two services. Thanks

Nagma

0 Kudos
AndyWright
Occasional Contributor

Hi Nagma,

I've actually called in a support ticket on this and am working with an Esri resource on it.  She is able to reproduce the problem, so if and when we get to some sort of resolution on it I'll post the results here.  Thanks for getting back to me though.

dotMorten_esri
Esri Notable Contributor

On Windows could you try running with Fiddler enabled and monitor the http requests? I'm guessing the server rejects the request for some reason - perhaps due to hitting some sort of size limitation?

0 Kudos
dotMorten_esri
Esri Notable Contributor

I got the log file from support, and I think I know what's going on. It looks like the "file" parameter is sent twice when we are doing larger uploads, and the server doesn't like that. Good news is this was already fixed for the upcoming release. Until the update ships, as a workaround, you could probably "fix" the outgoing request using the HttpRequestBegin. Something along the lines of this:

Esri.ArcGISRuntime.Http.ArcGISHttpClientHandler.HttpRequestBegin += (s, message) =>
{
    if (message.Method == HttpMethod.Post && message.Content is MultipartFormDataContent && message.RequestUri.OriginalString.EndsWith("/uploadPart"))
        {
        var content = message.Content as MultipartFormDataContent;
        var fileparameters = content.Where(c => c.Headers.ContentDisposition?.Name == "file" || c.Headers.ContentDisposition?.Name == "\"file\"");
        if (fileparameters.Count() > 1)
        {
            foreach (var file in fileparameters.OfType<StringContent>().Where(f => f.Headers.ContentDisposition != null))
                file.Headers.ContentDisposition.Name = "ignore";
        }
    }
};
0 Kudos
AndyWright
Occasional Contributor

Thanks for the response Morten.  Your support person was able to confirm that your code snippet does work with a few small modifications.  We are content with waiting for your next release at this point.

0 Kudos