C# 分析从ASP.NET核心接收的实体的客户端模型中的字节数组
我创建了一个SomeFile类: C#:C# 分析从ASP.NET核心接收的实体的客户端模型中的字节数组,c#,angular,typescript,asp.net-core,C#,Angular,Typescript,Asp.net Core,我创建了一个SomeFile类: C#: public class SomeFile { public byte[] Content { get; set; } public string MimeType { get; set; } public string Name { get; set; } } export interface SomeFile { Content: **Uint8Array** //am I correct to use
public class SomeFile
{
public byte[] Content { get; set; }
public string MimeType { get; set; }
public string Name { get; set; }
}
export interface SomeFile {
Content: **Uint8Array** //am I correct to use this type?
MimeType: string
Name: string
}
此文件以以下方式返回:
public async Task<IActionResult> GetFiles(string guid)
{
return Ok(new SomeFile() { Content = zippedFiles.ToArray(),
Name = $"zippedFiles.zip", MimeType = "application/x-zip-compressed" });
}
http服务获取的对象如下所示:
public downloadZip(): Observable<any> {
return this.http
.get(fooUrl)
.map((response: Response) => <SomeFile> response.json());
};
public downloadZip():可观察{
返回此文件。http
.get(fooUrl)
.map((response:response)=>response.json());
};
角度侧的内容属性应使用什么类型?
我使用Uint8Array
正确吗?
因为我得到了错误:
错误SyntaxError:JSON中位于位置0的意外标记p
可能我不应该做
.map((response:response)=>response.json())代码>?JSON格式无法处理二进制文件,因此需要将二进制信息编码为base64字符串,然后返回
因此,您必须将类型从byte[]
更改为string
不能返回json格式的二进制数据。您必须先在base64中对其进行编码,然后才能将其放入JSON中。@Tseng您的意思是System.Convert.ToBase64String(image)
@Tseng以及角度侧的Content
属性应使用何种类型?是的,您必须将其视为字符串(服务器侧和客户端)@Tseng请回答,我将其标记为asnwer。