davetimmins/ArcGIS.PCL

Use `MultipartFormDataContent` if POST body is too long

davetimmins opened this issue · 6 comments

Currently I just try to send the POST but for large payloads this will error and then I send as MultipartFormDataContent. Should instead check the POST content length and if longer than 65520 characters then just use MultipartFormDataContent see https://github.com/davetimmins/ArcGIS.PCL/blob/master/src/ArcGIS.ServiceModel/PortalGatewayBase.cs#L383

I'd like to take a stab at this. A simple check would be something like

HttpContent content = new FormUrlEncodedContent(parameters);
if(content.Headers.ContentLength > 65520)
{
    // create multipart
}

Or are you thinking of somehow calculating the length even before creating the first content?

edit: hmm, didn't mean to push that already... anyway, that's what I was thinking on how to solve this.

Hi, it would need to be done before creating the content as the error happens when the HttpContent content = new FormUrlEncodedContent(parameters); line runs, so there isn't a content.Headers.ContentLength then.

This test causes the warning

Yeah, I just got that when I looked over the code again. Seemed a bit too simple ;)

Will have a look at it again tomorrow.

Okay, had a second run at it: a56621b
Is that more or less ok for you?

I added tests in the subsequent commit; don't know if I found the right place for them, though: 06ecb7a

Yea looks good