0

I'm using angular app with .net core backend.

What I want to do, is to do a simple file upload app.

To c# controller I'm sending this json:

{"name":"test","extension":".txt","dateCreated":"2017-12-11T10:59:19.156Z","dateModified":"2017-12-11T10:59:19.156Z","data":{"0":89,"1":13,"2":10,"3":49,"4":48,"5":48,"6":13,"7":10,"8":69,"9":13,"10":10,"11":89,"12":13,"13":10,"14":53,"15":48,"16":13,"17":10,"18":72}}

It is formed by this TS class

export class File {
    id: number;
    name: string;
    data: Uint8Array;
    dateCreated: Date;
    dateModified: Date;
    extension: string;
}

Controller looks like

// POST: api/Test/Files
[HttpPost("[action]")]
public async Task<IActionResult> Files([FromBody] Files file)

And my Files class looks like

public partial class Files
{
    public int id { get; set; }
    public string name { get; set; }
    public byte[] data { get; set; }
    public DateTime dateCreated { get; set; }
    public DateTime dateModified { get; set; }
    public string extension { get; set; }
}

Response I'm getting:

{
  "data.0": [
    "The input was not valid."
  ]
}

I think the problem is that my controller can't convert from Uint8Array to byte[], but I cant seem to find the solution.

user3083761
  • 81
  • 1
  • 1
  • 7
  • If you remove `data` (from the JS and the C#) does the problem persist? – mjwills Dec 11 '17 at 12:13
  • no, the problem does not exist anymore – user3083761 Dec 11 '17 at 12:18
  • @EricLease I think C# (.net core to be exact) doesn't have Uint8Array type. In other question i found out that byte type in c# is equal to Uint8, so I assumed that Uint8Array would be the same as byte[]. But something is not quite right here – user3083761 Dec 11 '17 at 12:25
  • @mjwills no idea how I missed that one. Trying the fix now, will update if it worked or not. – user3083761 Dec 11 '17 at 12:28

0 Answers0