Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagekit-javascript",
"version": "3.0.1",
"version": "3.0.2",
"description": "Javascript SDK for using ImageKit.io in the browser",
"main": "dist/imagekit.cjs.js",
"module": "dist/imagekit.esm.js",
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/UploadOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ export interface UploadOptions {
* Optional XMLHttpRequest object that you can send for upload API request. You can listen to `progress` and other events on this object for any custom logic.
*/
xhr?: XMLHttpRequest

/**
* Optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
*/
checks?: string
}
2 changes: 2 additions & 0 deletions src/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export const upload = (
} else if(key === "transformation" && typeof uploadOptions.transformation === "object" &&
uploadOptions.transformation !== null) {
formData.append(key, JSON.stringify(uploadOptions.transformation));
} else if (key === 'checks' && uploadOptions.checks) {
formData.append("checks", uploadOptions.checks);
} else if(uploadOptions[key] !== undefined) {
formData.append(key, String(uploadOptions[key]));
}
Expand Down
30 changes: 30 additions & 0 deletions test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,4 +1309,34 @@ describe("File upload", function () {
expect(callback.calledOnce).to.be.true;
sinon.assert.calledWith(callback, errRes, null);
});

it("With checks option", async function () {
const fileOptions = {
...securityParameters,
fileName: "test_file_name",
file: "test_file",
responseFields: "tags, customCoordinates, isPrivateFile, metadata",
useUniqueFileName: false,
checks: "'request.folder' : '/'",
};
var callback = sinon.spy();

imagekit.upload(fileOptions, callback);

expect(server.requests.length).to.be.equal(1);
await sleep();
successUploadResponse();
await sleep();

var arg = server.requests[0].requestBody;
expect(arg.get("file")).to.be.equal("test_file");
expect(arg.get("fileName")).to.be.equal("test_file_name");
expect(arg.get("responseFields")).to.be.equal("tags, customCoordinates, isPrivateFile, metadata");
expect(arg.get("useUniqueFileName")).to.be.equal("false");
expect(arg.get("publicKey")).to.be.equal("test_public_key");
expect(arg.get('checks')).to.be.equal("'request.folder' : '/'");

expect(callback.calledOnce).to.be.true;
sinon.assert.calledWith(callback, null, uploadSuccessResponseObj);
});
});