gregoryp
gregoryp

Reputation: 1009

Send a base64 image from View to a ASP.NET Controller

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.

Upvotes: 1

Views: 1062

Answers (1)

Ahmar
Ahmar

Reputation: 3867

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)
{

}

Upvotes: 2

Related Questions