0
我创建了一个SomeFile类:解析字节数组核心
C#:
public class SomeFile
{
public byte[] Content { get; set; }
public string MimeType { get; set; }
public string Name { get; set; }
}
且该文件是在这样的方式返回:
public async Task<IActionResult> GetFiles(string guid)
{
return Ok(new SomeFile() { Content = zippedFiles.ToArray(),
Name = $"zippedFiles.zip", MimeType = "application/x-zip-compressed" });
}
在角边,我创建的模型文件:
角:
export interface SomeFile {
Content: **Uint8Array** //am I correct to use this type?
MimeType: string
Name: string
}
和HTTP服务获取该对象是这样的:
public downloadZip(): Observable<any> {
return this.http
.get(fooUrl)
.map((response: Response) => <SomeFile> response.json());
};
我应该使用内容酒店在角侧什么类型的?我正确的使用Uint8Array
? 因为我得到的错误:
ERROR SyntaxError: Unexpected token P in JSON at position 0
可能是我不应该做.map((response: Response) => <SomeFile> response.json());
?
你不能在json中返回二进制数据。在将它放入JSON之前,您必须使用base64进行编码。 – Tseng
@Tseng你的意思是? 'System.Convert.ToBase64String(image)' – StepUp
@Tseng以及我应该在Angular的'Content'属性中使用什么类型? – StepUp