我正在尝试使用s3FS在s3bucket上传图像。存储桶创建成功,但不知何故,我试图上传图像的api,给我一个错误,说你的路径没有定义。但是桶是在aws中创建的,但是图像不存在。
app.js
var express = require('express');
var mongoose = require('mongoose');
var fs = require('fs');
var S3FS = require('s3fs');
var s3fsImpl = new S3FS('folder', {
accessKeyId: 'id',
secretAccessKey: 'key'
});
s3fsImpl.create();
var multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty();
var bodyParser = require('body-parser');
var jwt = require('jsonwebtoken');
// var multer = require('multer');
// var uuid = require("uuid");
var app = express();
var config = require('./config.js');
var morgan = require('morgan');
// var path = require('path');
var port = process.env.PORT || 3000;
var foodtrucklist = require('./controller/foodtrucklist.js');
var login = require('./controller/login.js');
var itemInfo = require('./controller/item_info.js');
var review = require('./controller/reviews.js');
var popularitems = require('./controller/popularitems.js');
var foodtruck = require('./model/datafoodtruck');
var truckData = require('./model/foodtruck.js');
var webToken = require('./controller/webtoken.js');
var userprofile = require('./controller/userprofile.js');
var notificationdata = require('./model/dataNotifications.js');
var notification = require('./controller/notifications.js');
var foodtruckItemList = require('./controller/item_list_foodtruck.js');
var orderList = require('./controller/orders_foodtruck.js');
var ordermanagement = require('./controller/ordermanagement.js');
var db = mongoose.connect('mongodb://127.0.0.1:27017/quflip');
mongoose.connection.once('connected', function() {
console.log("Connected to database")
foodtruck.save(function(err, foodtrucks) {
if (err) res.send(err);
});
notificationdata.save(function(err, notifs) {
if (err) res.send(err);
});
});
app.use(multipartyMiddleware);
app.post('/testupload', function(req, res) {
var file = req.files.file;
var stream = fs.creatReadStream(file.path);
return s3fsImpl.writeFile(file.originalFilename, stream).then(function() {
fs.unlink(file.path, function(err) {
if (err) console.error(err);
})
res.json({
status:'200',
message:'uploaded'
})
})
});
错误
TypeError: Cannot read property 'path' of undefined
<br> at C:\Users\anand\quFlipApi\app.js:64:41
<br> at Layer.handle [as handle_request] (C:\Users\anand\quFlipApi\node_modules\express\lib\router\layer.js:95:5)
<br> at next (C:\Users\anand\quFlipApi\node_modules\express\lib\router\route.js:131:13)
<br> at Route.dispatch (C:\Users\anand\quFlipApi\node_modules\express\lib\router\route.js:112:3)
<br> at Layer.handle [as handle_request] (C:\Users\anand\quFlipApi\node_modules\express\lib\router\layer.js:95:5)
<br> at C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:277:22
<br> at Function.process_params (C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:330:12)
<br> at next (C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:271:10)
<br> at multipart (C:\Users\anand\quFlipApi\node_modules\connect-multiparty\index.js:50:53)
<br> at Layer.handle [as handle_request] (C:\Users\anand\quFlipApi\node_modules\express\lib\router\layer.js:95:5)
<br> at trim_prefix (C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:312:13)
<br> at C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:280:7
<br> at Function.process_params (C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:330:12)
<br> at next (C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:271:10)
<br> at expressInit (C:\Users\anand\quFlipApi\node_modules\express\lib\middleware\init.js:33:5)
<br> at Layer.handle [as handle_request] (C:\Users\anand\quFlipApi\node_modules\express\lib\router\layer.js:95:5)
<br> at trim_prefix (C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:312:13)
<br> at C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:280:7
<br> at Function.process_params (C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:330:12)
<br> at next (C:\Users\anand\quFlipApi\node_modules\express\lib\router\index.js:271:10)
<br> at query (C:\Users\anand\quFlipApi\node_modules\express\lib\middleware\query.js:44:5)
<br> at Layer.handle [as handle_request] (C:\Users\anand\quFlipApi\node_modules\express\lib\router\layer.js:95:5)