Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obengwilliam/971f8fa4c6955b5499ca7d5685aad9b6 to your computer and use it in GitHub Desktop.
Save obengwilliam/971f8fa4c6955b5499ca7d5685aad9b6 to your computer and use it in GitHub Desktop.
Node test upload file multi part superagent plus supertest
var request = require('supertest');
var fs = require('fs');
var reqData = {
title: 'Rahh!',
fileName: 'test-image.jpeg'
};
var req = request(context.app) //context.app = your express object
.post('/v1/images')
.set('Authorization', 'Bearer ' + context.token);
req
.part()
.set('Content-Disposition', 'form-data; name="content"; filename="' + reqData.fileName + '"')
.set('Content-Type', 'image/jpeg')
.write(fs.readFileSync((__dirname + '/../fixtures/' + reqData.fileName))); //read the file
req
.part()
.set('Content-Disposition', 'form-data; name="title"')
.write(reqData.title);
req.end(function(err, res) {
//do your tests over here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment