diff --git a/packages/google-cloud-vision/src/index.js b/packages/google-cloud-vision/src/index.js index d50065948bc..9c706e4c148 100644 --- a/packages/google-cloud-vision/src/index.js +++ b/packages/google-cloud-vision/src/index.js @@ -1269,6 +1269,12 @@ Vision.findImages_ = function(images, callback) { images = arrify(images); function findImage(image, callback) { + if (Buffer.isBuffer(image)) { + callback(null, { + content: image.toString('base64') + }); + return; + } if (image instanceof Storage.File) { callback(null, { source: { diff --git a/packages/google-cloud-vision/system-test/vision.js b/packages/google-cloud-vision/system-test/vision.js index 56b94bd5080..16ab6b7f8ce 100644 --- a/packages/google-cloud-vision/system-test/vision.js +++ b/packages/google-cloud-vision/system-test/vision.js @@ -66,6 +66,20 @@ describe('Vision', function() { }); }); + it('should detect from a Buffer', function(done) { + var buffer = fs.readFileSync(IMAGES.logo); + vision.detect(buffer, ['logos'], function(err, logos) { + assert.ifError(err); + + var expected = ['Google']; + expected.errors = []; + + assert.deepEqual(logos, expected); + + done(); + }); + }); + describe('single image', function() { var TYPES = ['faces', 'labels', 'safeSearch']; diff --git a/packages/google-cloud-vision/test/index.js b/packages/google-cloud-vision/test/index.js index 83ec3b90175..c3abee30efc 100644 --- a/packages/google-cloud-vision/test/index.js +++ b/packages/google-cloud-vision/test/index.js @@ -949,6 +949,22 @@ describe('Vision', function() { }); }); + + it('should get content from a buffer', function(done) { + var base64String = 'aGVsbG8gd29ybGQ='; + var buffer = new Buffer(base64String, 'base64'); + + Vision.findImages_(buffer, function(err, images) { + assert.ifError(err); + assert.deepEqual(images, [ + { + content: base64String + } + ]); + done(); + }); + }); + it('should return an error when file cannot be found', function(done) { Vision.findImages_('./not-real-file.png', function(err) { assert.strictEqual(err.code, 'ENOENT');