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: '/'
}
}