【问题标题】:return only the image from an object file仅返回目标文件中的图像
【发布时间】:2018-04-03 12:56:38
【问题描述】:

我正在将 base64 编码图像从服务器拉到网站,并希望自动使用该图像。图像位于对象文件中,我不确定如何从对象中提取图像。

服务器使用(Node.js 服务器)发送对象:

res.send(result[0]);

网站获取请求并显示代码:

getImage() {
this.httpClient.get('http://ip_address/route/imagename')
  .subscribe(data => {
    this.getImg = data;
    console.log(data);
  });

结果是一个包含图像的对象,但我希望图像在对象之外单独显示。我不知道这种需求是否发生在服务器或网站上,但我不知道这两种方式.. console log image on website link

【问题讨论】:

  • console.log(data.image);
  • data.image 在控制台日志中工作,但在将其分配给以下变量时无法正确构建:var baseImg = data.image;@nikhil

标签: javascript object base64 object-files


【解决方案1】:

我需要将数据文件保存到一个变量中,然后将其保存到另一个变量中,在第一个变量中指定我想要的部分。喜欢:

this.httpClient.get('ip_address/images/' + imgName)
  .subscribe(data => {
    this.imageData = data;
    this.base64image = (this.imageData.image);

this.base64image 然后可以用作 base64 代码。

【讨论】:

    猜你喜欢
    • 2016-12-25
    • 1970-01-01
    • 2022-01-15
    • 2020-11-24
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多