Skip to content

Commit 8cfd263

Browse files
ANKUR DWIVEDIANKUR DWIVEDI
authored andcommitted
added checks paramter
1 parent 8166889 commit 8cfd263

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

libs/interfaces/UploadOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ export interface UploadOptions {
108108
[key: string]: string | number | boolean | Array<string | number | boolean>;
109109
},
110110
transformation?: Transformation
111+
/**
112+
* Optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
113+
*/
114+
checks?: string
111115
}

libs/upload/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export default function (
9292
} else if (key === "transformation" && typeof uploadOptions.transformation === "object" &&
9393
uploadOptions.transformation !== null) {
9494
form.append(key, JSON.stringify(uploadOptions.transformation));
95+
} else if (key === "checks" && uploadOptions.checks) {
96+
form.append(key, uploadOptions.checks);
9597
} else {
9698
form.append(key, String(uploadOptions[key]));
9799
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit",
3-
"version": "5.0.1",
3+
"version": "5.0.2",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

tests/upload.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,28 @@ describe("File upload", function () {
548548
expect(callback.calledOnce).to.be.true;
549549
sinon.assert.calledWith(callback, errRes, null);
550550
});
551+
552+
it("With checks option", function (done) {
553+
const fileOptions = {
554+
fileName: "test_file_name",
555+
file: "test_file_content",
556+
checks: "'request.folder' : '/'",
557+
};
558+
559+
var callback = sinon.spy();
560+
561+
const scope = nock("https://upload.imagekit.io/api")
562+
.post("/v1/files/upload")
563+
.basicAuth({ user: initializationParams.privateKey, pass: "" })
564+
.reply(200, function (uri, requestBody) {
565+
expect(this.req.headers["content-type"]).include("multipart/form-data; boundary=---------------------");
566+
var boundary = this.req.headers["content-type"].replace("multipart/form-data; boundary=", "");
567+
checkFormData({ requestBody, boundary, fieldName: "fileName", fieldValue: fileOptions.fileName });
568+
checkFormData({ requestBody, boundary, fieldName: "file", fieldValue: fileOptions.file });
569+
checkFormData({ requestBody, boundary, fieldName: "checks", fieldValue: fileOptions.checks });
570+
done();
571+
});
572+
573+
imagekit.upload(fileOptions, callback);
574+
});
551575
});

0 commit comments

Comments
 (0)