Naruto
Naruto

Reputation: 708

I'm not getting any data in the api controller when posting the base64 data

My ajax call:

$http({
    method: 'POST',     
    headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },     
    url: myURL,     
    data:  { "data": content },    
    dataType: 'json'    
})

My api controller is

[Route("upload")]
[AcceptVerbs("POST")]
public string upload([FromBody]byte[] data) {
    return "";
}

Upvotes: 0

Views: 330

Answers (1)

Naruto
Naruto

Reputation: 708

I sent the data as the string and converted to Base64 on the controller. It worked for me.

It seems there is one more way to do it that is writing a custom MediaTypeFormatter.

Upvotes: 2

Related Questions