Node js中的Socket连接超时错误

编程入门 行业动态 更新时间:2024-10-05 05:20:37

Node js中的Socket连接超时<a href=https://www.elefans.com/category/jswz/34/1771449.html style=错误"/>

Node js中的Socket连接超时错误

我一直无法在 Node JS 中将图像上传到 cloudinary,因为当我尝试时出现此错误

Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout 
 {
   error: Error [ERR_SOCKET_CONNECTION_TIMEOUT]: Socket connection timeout
       at new NodeError (node:internal/errors:399:5)
       at internalConnectMultiple (node:net:1099:20)
       at Timeout.internalConnectMultipleTimeout (node:net:1638:3)
       at listOnTimeout (node:internal/timers:575:11)
       at process.processTimers (node:internal/timers:514:7) {
     code: 'ERR_SOCKET_CONNECTION_TIMEOUT'
   }
 }

有时会上传图片,有时不会。我在网上查了一下,它说互联网连接很差,但我的互联网已经足够好了,我已经将整个应用程序 dockerized,所以如果这与它有关,我就知道了。

const addProduct = async (req: Request, res: Response, next: NextFunction) => {
  const {
    title,
    snippet,
    description,
    quantity,
    price,
    coverImage,
    imageArray,
    category,
  } = req.body;
  try {
    cloudinary.api
      .ping()
      .then((res) => {
        console.log(`Cloudinary connection ${res.status}`);
      })
      .catch((err) => console.log(err));

    const imageUrlArray: Array<imageObjectType> = [];
    const coverImageUpload = await cloudinary.uploader.upload(coverImage);
    if (imageArray !== undefined) {
      for (let i = 0; i < imageArray.length; i++) {
        const image = await cloudinary.uploader.upload(imageArray[i]);
        imageUrlArray.push({
          publicId: image.public_id,
          secureUrl: image.secure_url,
        });
      }
    }
    console.log(req.seller);
    const product = await Product.create({
      title: title,
      snippet: snippet,
      description: description,
      quantity: quantity,
      price: price,
      coverImage: {
        publicId: coverImageUpload.public_id,
        secureUrl: coverImageUpload.secure_url,
      },
      imageArray: imageUrlArray,
      category: category,
      sellerId: req.seller,
    });
    console.log(product);
    if (product) {
      res.status(200).json({
        message: "Product added",
        category: category,
      });
    }
  } catch (err) {
    console.log(err);
  }
};

这是我上传图像的地方,它在我尝试 ping 到 cloudinary 的地方给了我错误。

回答如下:

更多推荐

Node js中的Socket连接超时错误

本文发布于:2024-05-30 19:55:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770863.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Node   js   Socket

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!