Skip to content

Commit

Permalink
Merge pull request #67 from imagekit-developer/dev
Browse files Browse the repository at this point in the history
Remove upload file size limit from Node.js SDK
  • Loading branch information
nikniv authored Nov 24, 2022
2 parents c82a69a + 45aca40 commit a7ae5a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
25 changes: 23 additions & 2 deletions tests/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -165,6 +165,27 @@ 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(15000347);
})

imagekit.upload(fileOptions, function (err, result) {
expect(err).to.equal(null)
done();
});
});

it('Missing useUniqueFileName', function (done) {
const fileOptions = {
Expand Down Expand Up @@ -352,4 +373,4 @@ describe("File upload", function () {
done();
})
});
});
});
1 change: 1 addition & 0 deletions utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function request<T, E extends Error> (
username: defaultOptions.privateKey || "",
password: "",
},
maxBodyLength: Infinity,
};

if (typeof requestOptions.json === "object") options.data = requestOptions.json;
Expand Down

0 comments on commit a7ae5a1

Please sign in to comment.