我正在使用.net核心后端的角度应用。
我想做的是做一个简单的文件上传应用程序。
对于c#controller我发送这个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}}
由此TS类组成
export class File {
id: number;
name: string;
data: Uint8Array;
dateCreated: Date;
dateModified: Date;
extension: string;
}
控制器看起来像
// POST: api/Test/Files
[HttpPost("[action]")]
public async Task<IActionResult> Files([FromBody] Files file)
我的文件类看起来像
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; }
}
我得到的回应:
{
"data.0": [
"The input was not valid."
]
}
我认为问题是我的控制器无法从 Uint8Array 转换为 byte [] ,但我似乎无法找到解决方案。