ajax hapi上传文件,node.js - Upload image to server - Hapi.js - Stack Overflow

I'm trying to upload an image to my server, and then save it to MongoDB. I'm using Hapi.js, React.js, Flux and Mongoose.

What I get in the payload is the following. Is this the path to the image?

{ path: '/var/folders/rl/6ygb2kgx7xnbkhnrpdxlbcl80000gp/T/1430991015360-27136-94254437ff20c8ce',

bytes: 68 }

Sorry if this question is a bit long, but I wanted to include all the steps.

Here is the form:

Here is the handleSubmit:

handleSubmit: function(e){

e.preventDefault();

var image = React.findDOMNode(this.refs.image).value;

var data = {

image: image

};

ActionCreators.saveImage(data);

},

Then, ActionCreators passes it on to APIUtils:

saveImage: function(data){

APIUtils.saveImage(data);

}

Finally, APIUtils sends the image as an AJAX request to the server:

saveImage: function(data){

Request.post('/api/image')

.send(data)

.end(function(err,res){

// do something with the response later on

});

}

Now, I'm trying to get access to this image on the server. Server.js:

{

path: '/api/image',

method: ['POST'],

config: {

payload: {

output:'file',

maxBytes:209715200,

parse: false

},

auth: {

strategy: 'session',

mode: 'try'

},

handler: function(request,reply){

var payload = request.payload;

console.log('payload: ', payload);

},

plugins: {

'hapi-auth-cookie': {

reddirectTo: '/'

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值