上传照片时,错误:发送照片后无法设置标题,

编程入门 行业动态 更新时间:2024-10-09 10:30:17

上传照<a href=https://www.elefans.com/category/jswz/34/1702628.html style=片时,错误:发送照片后无法设置标题,"/>

上传照片时,错误:发送照片后无法设置标题,

我试图通过api上传照片,此api使用axios消耗了另一个api,但是当我使用api上传时,它给出了错误:

错误:发送后无法设置标题,

当我在axios进程将错误抛出到catch块后调试res.status时

我想念东西吗,这是代码:

upload: async (req, res) => {
    const { subscriberId } = req.query;
    const file = req.file;

    if (!file) {
      return res
        .status(httpStatus.forbidden)
        .json({
          message: 'No File  Found'
        });
    }

    try {
      const form = new FormData();
      // console.log(form);
      form.append('file', 
        file.buffer,
        file.originalname
      );

      await axios.post(`${config.get('UPLOAD_PHOTO')}?subscriberId=${subscriberId}`, form, 
        {
          headers: {
            'api-key': `${config.get('API_KEY_CORE_SERVICE')}`,
            'Request-Id': req.requestId,
            'Content-Type': `multipart/form-data; boundary=${form._boundary}`
          }
        })
        .catch((error) => {
          // console.log(error.response.data)
          res.status(httpStatus.internalServerError).json({
            success: false,
            message: error.message,
            code: errorCodes.internalServerError
          });
        });

      return res.status(httpStatus.ok).json({
        success: true,
        status: httpStatus.ok,
        message: 'Successfully Upload Photo',
      });
    } catch (e) {
      return res.status(e.statusCode || httpStatus.internalServerError).json({
        success: false,
        message: (e.error && e.error.message) || e.message || e,
        code: errorCodes.internalServerError
      });
    }
回答如下:

您可以删除它

更多推荐

上传照片时,错误:发送照片后无法设置标题,

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

发布评论

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

>www.elefans.com

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