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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,14 @@ Sample usage
imagekit.upload({
file: file.files[0],
fileName: "abc1.jpg",
tags: ["tag1"]
tags: ["tag1"],
extensions: [
{
name: "aws-auto-tagging",
minConfidence: 80,
maxTags: 10
}
]
}, function(err, result) {
console.log(arguments);
console.log(imagekit.url({
Expand Down
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": "1.4.1",
"version": "1.4.2",
"description": "Javascript SDK for using ImageKit.io in the browser",
"main": "dist/imagekit.cjs.js",
"module": "dist/imagekit.esm.js",
Expand Down
9 changes: 8 additions & 1 deletion samples/sample-app/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ html
imagekit.upload({
file : file.files[0],
fileName : file.files[0].name || "test_image.jpg",
tags : ["test_tag_1"]
tags : ["test_tag_1"],
//- extensions: [
//- {
//- name: "aws-auto-tagging",
//- minConfidence: 80,
//- maxTags: 10
//- }
//- ],
}, function(err, result) {
if (err) {
statusEl.innerHTML = "Error uploading image. "+ err.message;
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/UploadOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ export interface UploadOptions {
* For example, set the value of this field to tags,customCoordinates,isPrivateFile,metadata to get value of tags, customCoordinates, isPrivateFile , and metadata in the response.
*/
responseFields?: string;
/*
* Object with array of extensions to be processed on the image.
*/
extensions?: object[];
/*
* Final status of pending extensions will be sent to this URL.
*/
webhookUrl?: string
}
8 changes: 8 additions & 0 deletions src/interfaces/UploadResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,12 @@ export interface UploadResponse {
* The metadata of the upload file. Use responseFields property in request to get the metadata returned in response of upload API.
*/
metadata?: Metadata;
/*
* AITags field is populated only because the google-auto-tagging extension was executed synchronously and it received a successresponse.
*/
AITags?: object[];
/*
* Field object which will contain the status of each extension at the time of completion of the update/upload request.
*/
extensionStatus?: { [key: string]: string }
}
13 changes: 11 additions & 2 deletions src/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,23 @@ export const upload = (
return;
}

if(uploadOptions.tags && Array.isArray(uploadOptions.tags))
{
uploadOptions.tags = String(uploadOptions.tags);
}

var formData = new FormData();
let i: keyof typeof uploadOptions;
for (i in uploadOptions) {
const param = uploadOptions[i];
if (typeof param !== "undefined") {
if (typeof param === "string" || typeof param === "boolean") {
if (typeof param === "string" || typeof param === "boolean") {
formData.append(i, String(param));
} else {
}
else if(Array.isArray(param)) {
formData.append(i, JSON.stringify(param));
}
else {
formData.append(i, param);
}
}
Expand Down
68 changes: 67 additions & 1 deletion test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const uploadSuccessResponseObj = {
"tags": ["t-shirt", "round-neck", "sale2019"],
"isPrivateFile": false,
"customCoordinates": null,
"fileType": "image"
"fileType": "image",
"AITags":[{"name":"Face","confidence":99.95,"source":"aws-auto-tagging"}],
"extensionStatus":{"aws-auto-tagging":"success"}
};

function successSignature() {
Expand Down Expand Up @@ -144,6 +146,22 @@ describe("File upload", function () {
sinon.assert.calledWith(callback, { message: "Missing authentication endpoint for upload", help: "" }, null);
});

it('Missing public key', function(){
const fileOptions = {
fileName: "test_file_name",
file: "test_file"
};

var callback = sinon.spy();

imagekit.upload(fileOptions, callback, {
publicKey : ""
});

expect(server.requests.length).to.be.equal(0);
sinon.assert.calledWith(callback, { message: "Missing public key for upload", help: "" }, null);
});

it('Auth endpoint network error handling', function () {
const fileOptions = {
fileName: "test_file_name",
Expand Down Expand Up @@ -336,6 +354,54 @@ describe("File upload", function () {
sinon.assert.calledWith(callback, null, uploadSuccessResponseObj);
});

it('With extensions parameter', function(){
const fileOptions = {
fileName: "test_file_name",
file: "test_file",
tags: "test_tag1,test_tag2",
customCoordinates: "10, 10, 100, 100",
responseFields: "tags, customCoordinates, isPrivateFile, metadata",
useUniqueFileName: false,
isPrivateFile: true,
extensions: [
{
name: "aws-auto-tagging",
minConfidence: 80,
maxTags: 10
}
],
webhookUrl: "https://your-domain/?appId=some-id"
};
var jsonStringifiedExtensions = JSON.stringify(fileOptions.extensions);
var callback = sinon.spy();

imagekit.upload(fileOptions, callback);

expect(server.requests.length).to.be.equal(1);
successSignature();
expect(server.requests.length).to.be.equal(2);
successUploadResponse();

var arg = server.requests[1].requestBody;

expect(arg.get('file')).to.be.equal("test_file");
expect(arg.get('fileName')).to.be.equal("test_file_name");
expect(arg.get('token')).to.be.equal("test_token");
expect(arg.get('expire')).to.be.equal("123");
expect(arg.get('signature')).to.be.equal("test_signature");
expect(arg.get('tags')).to.be.equal("test_tag1,test_tag2");
expect(arg.get('customCoordinates')).to.be.equal("10, 10, 100, 100");
expect(arg.get('responseFields')).to.be.equal("tags, customCoordinates, isPrivateFile, metadata");
expect(arg.get('useUniqueFileName')).to.be.equal('false');
expect(arg.get('isPrivateFile')).to.be.equal('true');
expect(arg.get('publicKey')).to.be.equal('test_public_key');
expect(arg.get('extensions')).to.be.equal(jsonStringifiedExtensions);
expect(arg.get('webhookUrl')).to.be.equal('https://your-domain/?appId=some-id')

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

it('Bare minimum request', function () {
const fileOptions = {
fileName: "test_file_name",
Expand Down