I'm trying to write a unit test on an amazon pre-signed upload url which takes a PUT request with a raw binary body.
Looking at examples for both the needle and request libraries, they all use form data examples. Can someone give me an example using either library that will send a local file up as a raw binary in the body of the request?
Request library https://github.com/request/request
Needle library https://github.com/tomas/needle
var filename = 'bunny.jpg';
var url = Amazon.getUploadUrl(filename);
var data = {
file: __dirname + '/' + filename,
content_type: 'image/jpeg'
};
var file = fs.createReadStream(__dirname + '/' + filename);
var request = require('needle');
request
.put(url, data, function(err, resp) {
console.log(resp.body.toString('utf-8'));
if (resp.statusCode !== 200) {
done(new Error(resp.statusMessage));
}
else
done(err);
});