1

I'm trying to send a base64 image from a View to a Controller.

I have the base64 stored in an input and I get it like this (working fine):

var photoBase64Captured = $('#txtPhotoBase64Captured').val();

Then in my View, I call the Controller and wait for a response:

$.get("@Url.Action("CheckFace", "User")", { base64: photoBase64Captured }, function (data) {

   var result = $.parseJSON(data);

   if (data != null) {

   }
});

When I try to call the Controller, I'm getting the following error in Chrome's console:

Failed to load resource: net::ERR_SPDY_PROTOCOL_ERROR

This is the Controller:

public async Task<ActionResult> CheckFace(string base64)
{

}

Any ideas why this is happening? Is the base64 too long to send to the Controller?

If I send other values to the Controller it works fine, so it is not a problem of the method.

9
  • 1
    Looks like Chrome issue, did you try another browser? Another possible issue is using $.get(), because sending (large) data to service should be done using POST request, with data in the body of request. Could you provide the code of corresponding controller's method? Commented Mar 2, 2018 at 13:39
  • @perozzo , check this link stackoverflow.com/questions/46863910/… Commented Mar 2, 2018 at 13:41
  • @apdevelop done! Commented Mar 2, 2018 at 13:48
  • @perozzo, Is it GET or POST controller action? Looks like you're exceeding limits of GET request (url length). Try the solution suggested above by @ray with POST request. Commented Mar 2, 2018 at 13:51
  • @apdevelop it's a GET since I'll not post anything, just return the result on the controller back to the view. Commented Mar 2, 2018 at 13:52

1 Answer 1

2

You need to use post for in this case. Image base64 to large for Get request.

$.post("@Url.Action("CheckFace", "User")", { base64: photoBase64Captured }, function (data) {

   var result = $.parseJSON(data);

   if (data != null) {

   }
});

[HttpPost]
public async Task<ActionResult> CheckFace(string base64)
{

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.