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