I get the '414 (Request-URI Too Long)' error when returning my image as a Base64 encoded string via the web api.
I currently have the following Action in my Web API Controller:
[System.Web.Http.Route("GetAllEvents")]
public async Task<IEnumerable<Event>> Get()
{
var vm = EventsViewModel.NewInstance;
return await vm.GetAllEvents();
}
And the vm.GetAllEvents() code:
public async Task<List<Event>> GetAllEvents()
{
var result = await DataStore.SelectAll();
result.ForEach(x =>
{
var byteArray = File.ReadAllBytes(x.ThumbnailPath);
x.ThumbnailEncoded = Convert.ToBase64String(byteArray);
});
return result;
}
I consume the WebAPI action as follow:
this.ajaxRetrieve = function(url, data, onSuccessCallback, onErrorCallback) {
$.ajax({
url: url,
data: data,
type: 'GET',
async: false,
dataType: 'JSON',
success: function(result) {
onSuccessCallback(result);
},
error: function(xhr, status, error) {
onErrorCallback(xhr, status, error);
}
});
}
What would be the better approach to take, to avoid this from happening?