【问题标题】:How to load images in nodeJS如何在 nodeJS 中加载图像
【发布时间】:2019-06-08 07:52:33
【问题描述】:

我刚开始使用 NodeJs,所以我不知道如何在 NodeJs 中显示图像。我已经提到了我的所有代码和我面临的问题。

exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {

  const email = user.email; // The email of the user.
  const displayName = user.displayName;  //The name of user 
  const image = user.photoURL;   // The image url of user
  // [END eventAttributes]

  return sendWelcomeEmail(email, displayName, image);
});

function sendWelcomeEmail(email, displayName , image) {
  const mailOptions = {
    from: `${APP_NAME} <noreply@firebase.com>`,
    to: email,
  };


mailOptions.subject = `Welcome to ${APP_NAME}!`;


    mailOptions.html = `
Hey ${name || ''}! Welcome to ${APP_NAME}.  
<br />
<img src="image">
<br/>
We hope you will enjoy our service. <br/> `;
  return mailTransport.sendMail(mailOptions).then(() => {
    return console.log('New welcome email sent to:', email);
  });
}

这里的图片没有在 html 中显示,所以我如何在下面的代码中传递包含图片 url 的 image 变量

<img src="image">

【问题讨论】:

  • NodeJS 是服务器端语言。图像通常显示在客户端或使用 ejs 等模板引擎进行服务器端渲染时。我还没有阅读您的问题,但它应该显示图像 url,图像 url 应该用于加载图像
  • @NoobieSatan 正是我只想使用图像 url 加载图像。基本上我从firebase欢迎电子邮件中复制了代码,我想显示图像,但我不知道我的问题有什么问题
  • 我没有将此问题标记为否定/否决。无论哪种方式,这将 ${image}Hey ${displayName || ''}! Welcome to ${APP_NAME}. \n\n We hope you will enjoy our service.;` 当你发送它时会变成这样.. http://somedomain/imageURl.jpghey Manik Welcome to AppName. We hope you will enjoy our service
  • 是的 @NoobieSatan 这是即将到来的输出,但不是 url 我如何在此处加载图像。我对此一无所知。如果你能帮助我,那对我很有帮助

标签: node.js firebase npm google-cloud-functions nodemailer


【解决方案1】:

电子邮件可以是文本,也可以包含 HTML。构成网页的 HTML 相同,可以包含使用 &lt;img src="{url here}"&gt; 标签的图像。因此,您应该在电子邮件中使用该标签,而不仅仅是输出图像 URL。 (您可能还需要将电子邮件的 Content-type 标头设置为 text/html 以使其正常显示。)

【讨论】:

  • 感谢您的帮助,在 html 的帮助下,我得到了一些显示图像的想法,但是通过使用 html,我遇到了我更新的问题,请检查并帮助。
【解决方案2】:

您必须将图像定义为:(未测试)

const image = <img src=${user.photoURL}/>

【讨论】:

  • 等我部署测试一下
猜你喜欢
  • 2021-09-25
  • 1970-01-01
  • 2018-03-29
  • 1970-01-01
  • 2013-08-18
  • 2015-11-13
  • 2012-11-07
  • 2012-07-20
  • 1970-01-01
相关资源
最近更新 更多