【问题标题】:simple Api for resizing image using typescript and sharp使用 typescript 和 sharp 调整图像大小的简单 Api
【发布时间】:2022-09-23 22:35:10
【问题描述】:

我正在制作一个 API,通过使用这样的 URL (http://localhost:3000/city/?name=encenadaport&width=200&height=200) 从数据库中获取图像 我编写了处理大小调整问题的代码和函数,问题是当我编写它给我的 URL 时 错误:ENOENT:没有这样的文件或目录,stat \'D:\\Programming\\Udacity_FWD\\Projects\\Image_Api\\assets\\thumbnail\\santamonica_300_200.png\' 当我重新运行它时 我认为它会在创建调整大小的图像之前发送响应我该怎么办 这是处理调整大小的部分

enter code here

  imgResize(imageLoc, name as string, width, height, newLocation);

  res.sendFile(`${newLocation}/${name}_${width}_${height}.png`);

 

    标签: node.js typescript sharp


    【解决方案1】:

    尝试制作 imgResize async 函数。然后awaitimgResize,然后再调用res.sendFile。我猜res.sendFileimgResize 完成处理之前被调用。

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      • 2019-05-17
      • 2020-08-08
      • 2021-09-06
      • 2019-08-18
      • 2011-12-23
      相关资源
      最近更新 更多