Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.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
Node.js S3FS节点和Express,未定义s3fsImpl_Node.js_Amazon Web Services_Amazon S3_Fs - Fatal编程技术网

Node.js S3FS节点和Express,未定义s3fsImpl

Node.js S3FS节点和Express,未定义s3fsImpl,node.js,amazon-web-services,amazon-s3,fs,Node.js,Amazon Web Services,Amazon S3,Fs,我试图使用node.js中的post请求将一个文件从我的节点服务器放入s3存储桶中。下面是我的节点服务器中设置路由的部分 // Get Dependencies const express = require('express'); const path = require('path'); const http = require('http'); const bodyParser = require('body-parser'); // Get API Routes const api =

我试图使用node.js中的post请求将一个文件从我的节点服务器放入s3存储桶中。下面是我的节点服务器中设置路由的部分

// Get Dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');

// Get API Routes
const api = require('./server/routes/api');

const app = express();

// Parse for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

// post static path to dist
app.use(express.static(path.join(__dirname,'dist')));

// Set our api routes
app.use('/api', api);
这里是api.js

const express = require('express');
const router = express.Router();
var fs = require('fs');
var S3FS = require('s3fs');
var s3fsImp1 = new S3FS('bucketname',{
        accessKeyId: 'xxxxxxxxx',
        secretAccessKey: 'xxxxxxxxxxxx'
});

router.get('/',(req,res) => {
    res.status(200).json({ message: 'Connected!' });
});

router.post('/upload',(req,res) => {
  var file = req.body.file;
  console.log(file);
  var stream = fs.createReadStream(file)
  return s3fsImpl.writeFile(file,stream).then(function(){
    fs.unlink(file,function(err){
      if(err)
        console.error(err);
    });
    res.send('done');
  }).catch(function (err) {
    return res.status(500).send({
      message: errorHandler.getErrorMessage(err)
    });
  });
});

module.exports = router;

当我从postman调用post方法时,Node抛出错误
ReferenceError:s3fsImpl未定义。任何帮助都将不胜感激。

我想您在声明中使用了1而不是字母“l”。这可能就是问题所在,它解决了!真不敢相信我竟然忽略了这一点!谢谢