From 20134b4daff0bb4ba9673acc508a61abb575eb8d Mon Sep 17 00:00:00 2001 From: Chinmay Chandak <25588684+CCAtAlvis@users.noreply.github.com> Date: Tue, 15 Dec 2020 15:34:22 +0530 Subject: [PATCH] Added buffer option to image upload Checks if the provided photo is a Buffer If its already a buffer, photo buffer is assigned to file Else its goes on to check isUrl() and finally fs.readFileSync() like before --- lib/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 9060571..67c2756 100644 --- a/lib/index.js +++ b/lib/index.js @@ -366,8 +366,12 @@ class Instagram { let file - // Needed to new method, if image is from url. - if (isUrl(photo)) { + // Needed to new method, + // if image is from buffer, + if (Buffer.isBuffer(photo)) { + file = photo + } else if (isUrl(photo)) { + // if image is from url. // Enconding: null is required, only this way a Buffer is returned file = await request.get({ url: photo, encoding: null }) } else {