Last active
August 29, 2015 14:02
-
-
Save yoitsro/d62b15df5f6de843e1e8 to your computer and use it in GitHub Desktop.
Hapi server injection with multipart form
This file contains hidden or 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
it('creates a new collection with an image as a binary buffer', function(done) { | |
var endpoint = '/collections'; | |
var url = SERVER_URL + endpoint; | |
var method = 'POST'; | |
var form = new FormData(); | |
form.append('json', {"name": "Red stuff collection","filter": {"colour": "red"}}); | |
form.append('image', require('fs').readFileSync('./test/data/image.jpg')); | |
var endpoint = '/collections'; | |
var url = SERVER_URL + endpoint; | |
var method = 'POST'; | |
server.inject({url: url, method: method, payload: form }, function(res) { | |
console.log(res.result); | |
expect(res.statusCode).to.equal(201); | |
done(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try bringing in the image as a readable stream instead of a buffer. Otherwise this is identical to the way I've successfully implemented it in the past.