TypeError: Cannot read property 'name' of null NodeJs Request module

TypeError: Cannot read property 'name' of null NodeJs Request module

我想用请求模块发送一个 post 请求。我的代码是这样截断的:

 let formData = new FormData();

   myArray.map((param, index) => {
      formData.append(param.name, param.value)
    })

    formData.append('file', fs.createReadStream(file.location), { filename: file.name });

    var options = {
      'method': 'POST',
      'url': 'https://shopify-video-production-core-originals.s3.amazonaws.com/',
      'headers': {
      },
      formData: formData,
    };

    let requestProm = async () => {
      return new Promise(resolve => {
        request(options, function (error, response) {
          if (error) {
            logger.error("Video Upload Failed")
            console.log(error)
          } else {
            logger.info("Video Upload Successfull");
            resolve(response);
          }
        })
      })

    }

    await requestProm()

但是我得到一个错误:

TypeError: Cannot read property 'name' of null

为什么我会收到这个错误?请帮忙!

编辑:我控制了我的 formData。没有空名称值。我在互联网上搜索但找不到任何解决方案。所以,我的 formData 是这样的:

FormData {
  _overheadLength: 1031,
  _valueLength: 832,
  _valuesToMeasure: [
    ReadStream {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      path: '/Users/usr/Desktop/vas-project/prj-shop-service/src/utils/../../temp_files/e43c7a3a37c3703a5e31964942d0f8e09d0d11e3796905320c639356bced17f2-jYX0RlERyX.mp4',
      fd: null,
      flags: 'r',
      mode: 438,
      start: undefined,
      end: Infinity,
      autoClose: true,
      pos: undefined,
      bytesRead: 0,
      closed: false,
      emit: [Function (anonymous)],
      [Symbol(kFs)]: [Object],
      [Symbol(kCapture)]: false,
      [Symbol(kIsPerformingIO)]: false
    }
  ],
  writable: false,
  readable: true,
  dataSize: 0,
  maxDataSize: 2097152,
  pauseStreams: true,
  _released: false,
  _streams: [
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="bucket"\r\n' +
      '\r\n',
    'shopify-video-production-core-originals',
    [Function: bound ],
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="key"\r\n' +
      '\r\n',
    'c/o/v/99de9caee4c04e3e9b46e76d520868f0.mp4',
    [Function: bound ],
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="policy"\r\n' +
      '\r\n',
    'eyJjb25kaXRpb25zIjpbWyJlcSIsIiRidWNrZXQiLCJzaG9waWZ5LXZpZGVvLXByb2R1Y3Rpb24tY29yZS1vcmlnaW5hbHMiXSxbImVxIiwiJGtleSIsImMvby92Lzk5ZGU5Y2FlZTRjMDRlM2U5YjQ2ZTc2ZDUyMDg2OGYwLm1wNCJdLFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLDE5MjM0NTcsMTkyMzQ1N10sWyJlcSIsIiRjYWNoZS1jb250cm9sIiwicHVibGljLCBtYXgtYWdlPTMxNTM2MDAwIl0sWyJlcSIsIiR4LWFtei1jcmVkZW50aWFsIiwiQUtJQVlPSTVLWjYySlFDVzYzTFUvMjAyMjAxMTMvdXMtZWFzdC0xL3MzL2F3czRfcmVxdWVzdCJdLFsiZXEiLCIkeC1hbXotYWxnb3JpdGhtIiwiQVdTNC1ITUFDLVNIQTI1NiJdLFsiZXEiLCIkeC1hbXotZGF0ZSIsIjIwMjIwMTEzVDE1NTg0M1oiXV0sImV4cGlyYXRpb24iOiIyMDIyLTAxLTEzVDE2OjU4OjQzWiJ9',
    [Function: bound ],
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="cache-control"\r\n' +
      '\r\n',
    'public, max-age=31536000',
    [Function: bound ],
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="x-amz-signature"\r\n' +
      '\r\n',
    '9db058a03d62b3ad48c7427e44b60a7d88834b2d67cca5bda792b44d613ab493',
    [Function: bound ],
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="x-amz-credential"\r\n' +
      '\r\n',
    'AKIAYOI5KZ62JQCW63LU/20220113/us-east-1/s3/aws4_request',
    [Function: bound ],
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="x-amz-algorithm"\r\n' +
      '\r\n',
    'AWS4-HMAC-SHA256',
    [Function: bound ],
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="x-amz-date"\r\n' +
      '\r\n',
    '20220113T155843Z',
    [Function: bound ],
    '----------------------------976490531239993416677931\r\n' +
      'Content-Disposition: form-data; name="file"; filename="jYX0RlERyX.mp4"\r\n' +
      'Content-Type: video/mp4\r\n' +
      '\r\n',
    DelayedStream {
      source: [ReadStream],
      dataSize: 0,
      maxDataSize: Infinity,
      pauseStream: true,
      _maxDataSizeExceeded: false,
      _released: false,
      _bufferedEvents: [Array],
      _events: [Object: null prototype],
      _eventsCount: 1
    },
    [Function: bound ]
  ],
  _currentStream: null,
  _insideLoop: false,
  _pendingNext: false,
  _boundary: '--------------------------976490531239993416677931'
}

Cannot read property '' of null表示对象的属性不存在。您可以做的是记录文件,然后检查 属性 'name' 是否存在。 记住:console.log() 是你在 nodejs 中最好的朋友(在一般编程中)

显然,表单数据已由请求承诺处理。您可以将表单数据作为对象传递。检查这个