Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用客户端javascript中的superagent发布多部分表单数据_Javascript_Node.js_Superagent - Fatal编程技术网

使用客户端javascript中的superagent发布多部分表单数据

使用客户端javascript中的superagent发布多部分表单数据,javascript,node.js,superagent,Javascript,Node.js,Superagent,我试图在客户端javascript上使用superagent向我的nodejs后端发出一个多部分表单post请求 只有attach()和part()方法出错 我的代码如下: superagent .post('/api/audio') .attach('file', '/music/music.mp3' ) .end(function(err, res){ console.log(res.text); }); 我是根据他们的文档写的,但它给了我一个错误: Uncaugh

我试图在客户端javascript上使用superagent向我的nodejs后端发出一个多部分表单post请求

只有attach()和part()方法出错

我的代码如下:

superagent
  .post('/api/audio')
  .attach('file', '/music/music.mp3' )
  .end(function(err, res){
    console.log(res.text);
  });
我是根据他们的文档写的,但它给了我一个错误:

Uncaught TypeError: superagent.post(...).attach is not a function

我哪里出错了?

您是否首先使用var superagent=require(“superagent”)之类的东西将superagent声明为变量;它基本上不是将超级代理识别为正确的对象,而链中的第一个方法就是抛出错误。如果先附加,它将在附加上执行相同的操作。@nopuck4you我在客户端使用superagent,而不是在nodejs中。即使我尝试执行var superagent=require('superagent');它抛出一个错误,表示未定义uncaughtreferenceerror:require。没有这一点,另一个post和get操作运行得非常好。“仅附加和部分”失败。我需要在第一行中查看导致superagent调用的代码。由于找不到Require等全局对象(如果您使用的是RequireJS、React或任何支持Require方法的框架),因此我认为您没有将供应商库正确加载到应用程序中。您是否直接向代码中添加superagent,如果是,如何添加?我正在执行类似的操作,请查看此容器