将byte [] / json DTO转换为Angular File

时间:2018-07-06 19:38:25

标签: spring angular typescript spring-mvc

您好,我在转换包含byte[]字段的JSON DTO Spring投影时遇到问题。

春季投影DTO:

public interface ProductBasicDto extends Serializable  {
    Long getId();
    String getCode();
    String getName();
    byte[] getImage();
// ...........
}

用@RestController注释的控制器的GET请求处理程序:

    @GetMapping("products")
    @ResponseStatus(code = HttpStatus.OK)
    public Page<ProductBasicDto> getProducts(Pageable pageable) {
        return productFacade.findAll(pageable);
    }

前端部分:

 this.httpClient
      .get<any>(this.API_URL_PRODUCTS)
      .map(data => self.convertToProduct(data)).subscribe(productAdminArray => {
        console.log(productAdminArray);
        this.dataChange.next(productAdminArray);

console.log输出:

code:"Code"
name: "Name"
image:"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExc
....

因此它返回json和奇怪字符串的混合图像数据。我需要将第一部分转换为前端模型对象(很简单),将第二部分转换为File []类型,因为我正在使用ng2FileInputService.add('fileName', file);-ng2-file-input包向用户显示/加载图像。

有人可以帮助我实现这种行为吗?我只想在一个请求中获取带有图像的DTO。

0 个答案:

没有答案