【问题标题】:Uploading File IN GraphQL在 GraphQL 中上传文件
【发布时间】:2021-11-01 17:46:38
【问题描述】:

从邮递员上传文件时出现此错误。

(node:13648) [DEP0135] DeprecationWarning: ReadStream.prototype.open() is deprecated

我的节点版本是 15.0.我正在使用 apollo-server-express。这是我的代码

export const processUpload = async (file) => {
  const {
    createReadStream, mimetype, encoding, filename
  } = await file;
  const path = `uploads/${uuid()}${filename}`;
  const stream = createReadStream();
  return new Promise((resolve, reject) => {
    stream
      .pipe(fs.createWriteStream(path))
      .on('finish', () => {
        resolve({
          success: true,
          message: 'Successfully Uploaded',
          mimetype,
          filename,
          encoding,
          location: path
        });
      })
      .on('error', (err) => {
        console.log('Error Event Emitted', err);
      });
  });
};

【问题讨论】:

    标签: node.js graphql apollo-server


    【解决方案1】:

    您的节点版本高,请在 package.js 文件中添加。

    "resolutions": {
        "**/**/fs-capacitor": "^6.2.0",
        "**/graphql-upload": "^11.0.0"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-03
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 2020-06-16
      • 2019-12-30
      相关资源
      最近更新 更多