如何将文件内容从打字稿传递到npm ogre?

时间:2020-06-24 08:10:54

标签: node.js angular typescript npm ogre

我安装了npm ogre并启动了端口号为3000的npm ogre服务器,

在使用localhost:3000/convert API的浏览器中,我可以将文件转换为正确的转换文件。

但是,我尝试了相同的API Angular,并且得到了响应:

"No File Provided".

请找到以下用于ogre服务器的代码和用于调用ogre服务器的Angular代码。

app.post('/convert', enableCors, function(req, res, next) {
    if (!req.files.upload || !req.files.upload.name) {
      res.status(400).json({error: true, msg: 'No file provided'})
      return
    }
    console.info('Ogre listening on port a');
    let ogr = ogr2ogr(req.files.upload.path)

    if (req.body.targetSrs) {
      ogr.project(req.body.targetSrs, req.body.sourceSrs)
    }

    if ('rfc7946' in req.body) {
      ogr.options(['-lco', 'RFC7946=YES'])
    }

    if ('skipFailures' in req.body) {
      ogr.skipfailures()
    }

    if (opts.timeout) {
      ogr.timeout(opts.timeout)
    }

    res.header(
      'Content-Type',
      'forcePlainText' in req.body
        ? 'text/plain; charset=utf-8'
        : 'application/json; charset=utf-8'
    )

    if ('forceDownload' in req.body) {
      res.attachment()
    }

    ogr.exec(function(er, data) {
      fs.unlink(req.files.upload.path, noop)

      if (isOgreFailureError(er)) {
        return res
          .status(400)
          .json({errors: er.message.replace('\n\n', '').split('\n')})
      }

      if (er) return next(er)

      if (req.body.callback) res.write(req.body.callback + '(')
      res.write(JSON.stringify(data))
      if (req.body.callback) res.write(')')
      res.end()
    })
  })

任何人都可以解释如何使用角度打字稿将文件传递到ogre服务器。请在下面找到我的电话通知代码:

const req = new HttpRequest('POST', `${this.baseUrl}/convert`, file, {
    reportProgress: true,
     responseType: 'json'
});

0 个答案:

没有答案