小编Cod*_*Bae的帖子

将缓冲区数据转换为图像

我如何将此缓冲区数据转换为图像,以便当循环结果并将其呈现在 img src 中时,它将呈现为用户可以看到的图像

我正在使用 ejs 来渲染它

     <span>
        <img class="user-with-avatar" src=<%=item.photo%> />
     </span>

Run Code Online (Sandbox Code Playgroud)

当我 console.log(result.data.photo) 时,我得到这个

{"type":"Buffer","data":[100,97,116,97,58,14,79,8,113,97,65,43,57,55,89,69,88,51,66,101,70,86,112,121,112,121,121,121,80,81,104]},
{"type":"Buffer","data":[100,97,116,97,58,14,79,8,113,97,65,43,57,55,89,69,88,51,66,101,70,86,112,121,112,121,121,121,80,81,104]},
{"type":"Buffer","data":[100,97,116,97,58,14,79,8,113,97,65,43,57,55,89,69,88,51,66,101,70,86,112,121,112,121,121,121,80,81,104]}

Run Code Online (Sandbox Code Playgroud)

我该如何用这个代码安排来修复它


    app.get('/products', function (req, res) {
            if (req.session.token && req.session.user_id) {
                let data = {
                    token: req.session.token,
                    id: req.session.user_id,
                }
                let url = `https:/url/product/get_products?id=${data.id}&token=${data.token}`
                functions.callAPIGet(
                    url,
                    function (error, result) {
                        res.render('products', {
                            result: result.data
                        })
                    }
                );
            } else {
                res.redirect('/login')
            }
        });

Run Code Online (Sandbox Code Playgroud)

javascript ejs node.js express

7
推荐指数
1
解决办法
3万
查看次数

MongoError: E11000 重复键错误集合: test.users 索引: email1_1 dup key: { email1: null }

每当我尝试注册用户时,它都会给我这个错误

我检查了 db 集合并且不存在这样的重复条目,让我知道我做错了什么?

仅供参考 - req.body.email 和 req.body.password 正在获取值。

我也检查了这篇文章,但没有帮助堆栈链接

如果我完全删除,那么它会插入文档,否则即使我在 local.email 中有一个条目,它也会抛出错误“重复”错误


    Server started on port 5000
    MongoDB Connected
    MongoError: E11000 duplicate key error collection: test.users index: email1_1 dup key: { email1: null }

     { driver: true,
      name: 'MongoError',
      index: 0,
      code: 11000,
      keyPattern: { email1: 1 },
      keyValue: { email1: null },
      errmsg: 'E11000 duplicate key error collection: test.users index: email1_1 dup key: { email1: null }',
      [Symbol(mongoErrorContextSymbol)]: {}
    }

Run Code Online (Sandbox Code Playgroud)

以下是我在 user.js 模型架构中的用户架构


    const mongoose = require('mongoose'); …
Run Code Online (Sandbox Code Playgroud)

javascript authentication mongodb node.js nodemailer

4
推荐指数
1
解决办法
7650
查看次数

错误:SMTPConnection._formatError 连接超时

错误:SMTPConnection._formatError 连接超时,不知道出了什么问题,无法发送邮件,请帮助我。我正在尝试使用 nodemailer 发送邮件,但我不断在控制台中收到此错误

    Error: Connection timeout
        at SMTPConnection._formatError (/home/codabae/Desktop/mailmonster/Backend/v1/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
        at listOnTimeout (internal/timers.js:531:17)
        at processTimers (internal/timers.js:475:7) {
      code: 'ETIMEDOUT',
      command: 'CONN'
    }
Run Code Online (Sandbox Code Playgroud)

这是我的 api,我不知道做错了什么,我从 mongodb 获取详细信息并将其填充到 nodmailer 字段中,我真的不知道做错了什么。

    router.post('/', auth, (req, res) => {
    const { to, cc, bcc, subject, message, attachment, smtpDetails } = req.body;

    if (!to || !subject || !message || !smtpDetails) return res.status(400).send('input cannot be empty')

    let transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
            user: '...@gmail.com',
            pass: '...'
        }
    });

    let mailOptions = {
        from:  '...@gmail.com',
        to: …
Run Code Online (Sandbox Code Playgroud)

javascript email mongodb node.js express

4
推荐指数
1
解决办法
7947
查看次数

如何使用 jQuery 设置活动链接列表项的样式

我正在使用 jQuery 检查浏览器 URL 是否与我的链接 href 中的 URL 匹配,问题是在我检查之后我试图将链接匹配的 li 标记类设置为“活动”,但下面的代码正在设置链接标记为活动而不是 li 标记

    $(function(){
        var current = location.pathname;
        $('#nav li a').each(function(){
            var $this = $(this);
            // if the current path is like this link, make it active
            if($this.attr('href') === current){
                $this.addClass('active');
            }
        })
    }) 

Run Code Online (Sandbox Code Playgroud)

html javascript css jquery dom

1
推荐指数
1
解决办法
67
查看次数

标签 统计

javascript ×4

node.js ×3

express ×2

mongodb ×2

authentication ×1

css ×1

dom ×1

ejs ×1

email ×1

html ×1

jquery ×1

nodemailer ×1