From 0f2a3725007deb9af2ea2021dc40858b93e51686 Mon Sep 17 00:00:00 2001 From: ABHINAV ANKIT <100715876+AbhinavAnkit09@users.noreply.github.com> Date: Thu, 24 Nov 2022 17:28:14 +0530 Subject: [PATCH 1/4] IK909-Max body length exceeded issue during upload via node SDK (#66) * set Axios http request body size to infinity * added test video of size larger than 10MB * Added test case Added test case for file upload of size larger than 10MB * removed extra white space * test case refactoring * 4.1.2 * Use static buffer in test instead of string Co-authored-by: Abhinav Ankit Co-authored-by: Nik <11422270+nikniv@users.noreply.github.com> --- package.json | 2 +- tests/upload.js | 23 +++++++++++++++++++++-- utils/request.ts | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6de5f99..22f845b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "imagekit", - "version": "4.1.1", + "version": "4.1.2", "description": "Offical NodeJS SDK for ImageKit.io integration", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/tests/upload.js b/tests/upload.js index f624e5f..bd60f22 100644 --- a/tests/upload.js +++ b/tests/upload.js @@ -147,7 +147,7 @@ describe("File upload", function () { imagekit.upload(fileOptions, callback); }); - it('Buffer file', function (done) { + it('Buffer file smaller than 10MB', function (done) { const fileOptions = { fileName: "test_file_name", file: fs.readFileSync(path.join(__dirname,"./data/test_image.jpg")) @@ -165,6 +165,25 @@ describe("File upload", function () { imagekit.upload(fileOptions); }); + + it('Buffer file larger than 10MB', function (done) { + const fileOptions = { + fileName: "test_file_name", + file: Buffer.alloc(15000000), // static buffer of 15 MB size + }; + + const scope = nock('https://upload.imagekit.io/api') + .post('/v1/files/upload') + .basicAuth({ user: initializationParams.privateKey, pass: '' }) + .reply(200, function (uri, requestBody) { + expect(this.req.headers["content-type"]).include("multipart/form-data; boundary=---------------------"); + var boundary = this.req.headers["content-type"].replace("multipart/form-data; boundary=",""); + expect(requestBody.length).equal(20000280); + done() + }) + + imagekit.upload(fileOptions); + }); it('Missing useUniqueFileName', function (done) { const fileOptions = { @@ -352,4 +371,4 @@ describe("File upload", function () { done(); }) }); -}); \ No newline at end of file +}); diff --git a/utils/request.ts b/utils/request.ts index f3bd24e..050afa5 100644 --- a/utils/request.ts +++ b/utils/request.ts @@ -17,6 +17,7 @@ export default function request ( username: defaultOptions.privateKey || "", password: "", }, + maxBodyLength: Infinity, }; if (typeof requestOptions.json === "object") options.data = requestOptions.json; From f0331d504fa4fe8fbd77998bfa1e6989b3fd556a Mon Sep 17 00:00:00 2001 From: Nik <11422270+nikniv@users.noreply.github.com> Date: Thu, 24 Nov 2022 17:55:15 +0530 Subject: [PATCH 2/4] Update test case --- tests/upload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/upload.js b/tests/upload.js index bd60f22..0527cf2 100644 --- a/tests/upload.js +++ b/tests/upload.js @@ -178,7 +178,7 @@ describe("File upload", function () { .reply(200, function (uri, requestBody) { expect(this.req.headers["content-type"]).include("multipart/form-data; boundary=---------------------"); var boundary = this.req.headers["content-type"].replace("multipart/form-data; boundary=",""); - expect(requestBody.length).equal(20000280); + expect(requestBody.length).equal(15000347); done() }) From 49f8436603318527144302f97d466287feebf0bc Mon Sep 17 00:00:00 2001 From: nikniv Date: Thu, 24 Nov 2022 18:55:42 +0530 Subject: [PATCH 3/4] retrigger build --- tests/upload.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/upload.js b/tests/upload.js index 0527cf2..f486071 100644 --- a/tests/upload.js +++ b/tests/upload.js @@ -279,6 +279,7 @@ describe("File upload", function () { imagekit.upload(fileOptions, callback); setTimeout( () => { + console.log(callback.called, callback.calledOnce) expect(callback.calledOnce).to.be.true; sinon.assert.calledWith(callback, null, uploadSuccessResponseObj); done(); From 45aca40ee6b94d133bf01d5cafea2ebf777d5cb2 Mon Sep 17 00:00:00 2001 From: Nik <11422270+nikniv@users.noreply.github.com> Date: Thu, 24 Nov 2022 19:43:35 +0530 Subject: [PATCH 4/4] Fix failing CI pipeline for Node 12 (#68) * add callback * update callback * remove log line --- tests/upload.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/upload.js b/tests/upload.js index f486071..fda54a0 100644 --- a/tests/upload.js +++ b/tests/upload.js @@ -179,10 +179,12 @@ describe("File upload", function () { expect(this.req.headers["content-type"]).include("multipart/form-data; boundary=---------------------"); var boundary = this.req.headers["content-type"].replace("multipart/form-data; boundary=",""); expect(requestBody.length).equal(15000347); - done() }) - imagekit.upload(fileOptions); + imagekit.upload(fileOptions, function (err, result) { + expect(err).to.equal(null) + done(); + }); }); it('Missing useUniqueFileName', function (done) { @@ -279,7 +281,6 @@ describe("File upload", function () { imagekit.upload(fileOptions, callback); setTimeout( () => { - console.log(callback.called, callback.calledOnce) expect(callback.calledOnce).to.be.true; sinon.assert.calledWith(callback, null, uploadSuccessResponseObj); done();