Created
July 7, 2014 19:14
-
-
Save petreboy14/161adacdb706d3aac4f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
routes.push({ | |
method : 'POST', | |
path : '/upload', | |
config: { | |
payload: { | |
parse: false, | |
output: 'stream', | |
maxBytes: 1073741824 | |
} | |
}, | |
handler: function(req, reply) { | |
var host = 'host'; | |
var route = '/upload'; | |
var formdata = {}; | |
var form = new multiparty.Form(); | |
form.on('error', function (err) { | |
console.log(err); | |
return reply(Hapi.error.internal(err)); | |
}); | |
form.on('part', function (part) { | |
console.log(part.name, part.filename) | |
if (!part.filename) return | |
var r = request.post(options, function (err, res, body) { | |
if (err) return reply(Hapi.error.internal(err)); | |
else { | |
console.log(body); | |
return reply(); | |
} | |
}); | |
var f = r.form(); | |
f.append('type', 'harcode a type') | |
f.append('stuff', 'hardcode stuff') | |
f.append('file', part, {filename: part.filename, contentType: part.headers['content-type']}) | |
//formdata[part.name] = part | |
//part.resume() | |
}) | |
form.on('field', function (name, value) { | |
formdata[name] = value | |
}) | |
form.on('close', function () { | |
console.log('close') | |
}) | |
form.parse(req.payload); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment