简体   繁体   English

Angular 5-不安全:数据:图像/八位字节流

[英]Angular 5 - unsafe:data:image/octet-stream

I have data represented in json ; 有用json表示的数据; my problem is that I cannot read images starting with data:image/octet-stream . 我的问题是我无法读取以data:image/octet-stream开头的data:image/octet-stream

During execution, the console print's an error that the string is unsafe. 在执行过程中,控制台打印错误提示该字符串不安全。 The error is as follows: 错误如下:

unsafe:data:image/octet-stream;base64,/9j/4AAQSkZJRgABAQEBMQExAAD/7S6...

I have tried a few examples, but they do not work; 我尝试了一些示例,但是它们没有用; they return a string of the images. 他们返回一串图像。 Below is the json data I am reading: 以下是我正在读取的json数据:

[
        {
            "id": 1,
            "name": "Albany",
            "manufacture": "Albany Superior Low Gi Sliced Brown Seed Bread 700g",
            "price": 15.49,
            "category": "Food",
            "type": "Breads",
            "image": "data:image/jpeg;base64,/9j/4AAQSkZJRgA..."
        },
        {
            "id": 2,
            "name": "Blue Ribbon",
            "manufacture": "Blue Ribbon Brown Plus Low Gi Bread 700g",
            "price": 13.99,
            "category": "Food",
            "type": "Breads",
            "image": "data:image/octet-stream;base64,/9j/4AAQSkZJRgABA..."
        },
        ...
    ]

I have a class in which I was trying to implement a hack to this problem: 我有一堂课,我试图在其中解决此问题:

export class MilkCreamComponent implements OnInit {

  allProducts: Array<Product> = [];
  quantity: number = 1;
  resultArray:any;
  milkProducts =[]

  constructor( private prod: ProductService, public _DomSanitizer: DomSanitizer) { }

  ngOnInit() {

    this.allProducts = JSON.parse(localStorage.getItem('product-data') );
    //console.log( JSON.stringify( this.allProducts ) );

    var productMilk = this.allProducts.filter(item => item.type === 'Milk');
    this.milkProducts = productMilk;

    console.log( productMilk );
  }
}

interface Product {

  id: number;
  name: string;
  manufacture: string;
  price: number;
  category: string;
  type: string;
  image: string;
}

And my html is as follows: 和我的HTML如下:

<tr *ngFor="let prod of milkProducts">
    <td><img src={{prod.image}}   width="120" height="130"/></td>
    <td>{{prod.name}}</td>
    <td>{{prod.manufacture}}</td>
    <td>R {{prod.price}}</td>

    <td><button class="btn btn-primary">data boy</button></td>
</tr>

I do not know how to solve this. 我不知道该怎么解决。

您的json中的图片网址是base64格式,首先您必须将base64转换为普通图片来源,然后才能在HTML模板上显示图片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将String转换为application / octet-stream Java - Convert String to application/octet-stream Java 生成 application/octet-stream 和 application/json - Producing application/octet-stream and application/json 如何将应用程序/八位字节流转换为要以 base64 或任何 jpeg 格式显示的图像? - How shall I convert application/octet-stream into image to be displayed in base64 or any jpeg format? 如何将 RestTemplate 与 application/octet-stream 响应类型一起使用 - How to use RestTemplate with application/octet-stream response type 如何将 Blob(八位字节流)读取到 JSON 对象? - How to read Blob (octet-stream) to JSON object? 找不到媒体类型= application / octet-stream的MessageBodyReader - MessageBodyReader not found for media type=application/octet-stream JSON.parse()用于类型为application / octet-stream的对象 - JSON.parse() for an Object of type application/octet-stream Azure IoT 中心中的消息路由返回应用程序/八位字节流 - Message Routing in Azure IoT Hub returning application/octet-stream PHP生成的JSON文件具有application / octet-stream mime类型 - JSON file generated by PHP has application/octet-stream mime type 如何使用RestAssured将“application / octet-stream”内容类型发布到RestAPI - How to post “application/octet-stream” content type to RestAPI using RestAssured
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM