1

I'm developing an Ionic 3 mobile application and using ASP.NET REST WebAPI 2 as my back-end.

I've been trying to pass a base64 string ( around 150kb big enocoded png image) to one of my webAPI methods without any success for the last couple of days.

My API call

Method that I'm calling in my WebAPI

The problem is that the WebApi doesn't seem to receive any values, as seen HERE

I'm sending my data with these HEADERS

Upon further inspection I noticed the following. I intercepted the api call with Postman and discovered that the webApi receives data, but cuts the data at 4079th character as seen HERE. Since the webAPI seems to cut the JSON string at 4079th character, the JSON itself isn't complete which (I'm guessing) is the reason why the webAPI can't read it and also why the values are all empty while debugging the webAPI method in Visual Studio.

Here is another interesting thing. In Chrome Development tools under the Network section I can see the API call with all the additional info. Chrome also shows the FULL base64 string as seen HERE.

Does anyone have any idea what's going on here? Has anyone else experienced similar problems before?

UPDATE 1:

I just added THIS to my Web.config as @evayly suggested.

I also tried adjusting the following values:

maxAllowedContentLength

maxRequestLength

aspnet:MaxJsonDeserializerMembers

but it didn't solve the problem.

UPDATE 2

Another part of interesting info:

If I manually edit the intercepted post in Postman by adding json closing tags - " } and resend it, the method reads the data without any problems. So i think the main problem is something cutting my json to 4079 characters --> creating a json string without the proper closing tags and thus making my json invalid.

Aljosa
  • 11
  • 2
  • check that link https://stackoverflow.com/a/38563143/1356478 – fofik Apr 17 '18 at 07:57
  • Hi, thank you for your suggestion. I've already tried changing maxAllowedContentLength, maxRequestLength and aspnet:MaxJsonDeserializerMembers in Web.config but i'm not seeing any changes. I'm trying to transfer encoded pictures that are small (around 150kb). As far as i understand it, those changes in Web.config would only be useful if i was trying to transfer larger files. – Aljosa Apr 17 '18 at 08:08
  • Did you increase maxReceivedMessageSize for your endpoint? – evayly Apr 17 '18 at 08:51
  • please see UPDATE 1 in the main post – Aljosa Apr 17 '18 at 09:58
  • The body of your post is a json object does it match the base64file type? check the type your post method accepts. To check change your post method to accept a dynamic object and you should see your data... I think everything else you have encountered is a red herring. – S Philp Apr 17 '18 at 10:04
  • Hi, the "Base64FileType" is a custom class that I've created and it accepts a string, which should be the right data type for reading base64 strings. Please check UPDATE 2. – Aljosa Apr 17 '18 at 10:19
  • Please add code inline rather than as a linked (or inline) image. – phuzi Apr 17 '18 at 10:42
  • did you try sending a short string like a few chars in length? – fofik Apr 17 '18 at 12:28
  • Hello, I did. WebAPI and the method accept short strings without any problems. – Aljosa Apr 17 '18 at 12:41

0 Answers0