Skip to content

Commit d7b2118

Browse files
authored
Merge pull request #61 from imagekit-developer/dev
Dev
2 parents 8afc7ed + d274fc6 commit d7b2118

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ The SDK provides a simple interface using the `.upload()` method to upload files
261261

262262
The `upload()` method requires mandatory `file` and the `fileName` parameter. In addition, it accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload).
263263

264-
Also, make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields, i.e. `signature`, `token`, and `expire`.
264+
Also, ensure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields, i.e. `signature`, `token`, and `expire`. In addition, the SDK adds a query parameter `t` with a random value to ensure that the request URL is unique and the response is not cached in [Safari iOS](https://github.com/imagekit-developer/imagekit-javascript/issues/59). Your backend can ignore this query parameter.
265265

266266
[Learn how to implement authenticationEndpoint](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#how-to-implement-authenticationendpoint-endpoint) on your server.
267267

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit-javascript",
3-
"version": "1.5.1",
3+
"version": "1.5.2",
44
"description": "Javascript SDK for using ImageKit.io in the browser",
55
"main": "dist/imagekit.cjs.js",
66
"module": "dist/imagekit.esm.js",

src/utils/request.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ export const generateSignatureToken = (
6565
return new Promise((resolve, reject) => {
6666
var xhr = new XMLHttpRequest();
6767
xhr.timeout = 60000;
68-
xhr.open('GET', authenticationEndpoint);
68+
var urlObj = new URL(authenticationEndpoint);
69+
urlObj.searchParams.set("t", Math.random().toString());
70+
xhr.open('GET', urlObj.toString());
6971
xhr.ontimeout = function (e) {
7072
return reject(errorMessages.AUTH_ENDPOINT_TIMEOUT);
7173
};

test/upload.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const uploadSuccessResponseObj = {
2727
};
2828

2929
function successSignature() {
30-
server.respondWith("GET", initializationParams.authenticationEndpoint,
30+
server.respondWith("GET", new RegExp(initializationParams.authenticationEndpoint + ".*"),
3131
[
3232
200,
3333
{ "Content-Type": "application/json" },
@@ -41,7 +41,7 @@ function successSignature() {
4141
}
4242

4343
function nonSuccessErrorSignature() {
44-
server.respondWith("GET", initializationParams.authenticationEndpoint,
44+
server.respondWith("GET", new RegExp(initializationParams.authenticationEndpoint + ".*"),
4545
[
4646
403,
4747
{ "Content-Type": "application/json" },
@@ -221,7 +221,7 @@ describe("File upload", function () {
221221
expect(server.requests.length).to.be.equal(2);
222222

223223
// Simulate non 200 response on authentication endpoint
224-
server.respondWith("GET", initializationParams.authenticationEndpoint,
224+
server.respondWith("GET", new RegExp(initializationParams.authenticationEndpoint + ".*"),
225225
[
226226
200,
227227
{ "Content-Type": "application/json" },
@@ -245,7 +245,7 @@ describe("File upload", function () {
245245
expect(server.requests.length).to.be.equal(2);
246246

247247
// Simulate non 200 response on authentication endpoint
248-
server.respondWith("GET", initializationParams.authenticationEndpoint,
248+
server.respondWith("GET", new RegExp(initializationParams.authenticationEndpoint + ".*"),
249249
[
250250
200,
251251
{ "Content-Type": "application/json" },
@@ -664,7 +664,7 @@ describe("File upload", function () {
664664
});
665665

666666
expect(server.requests.length).to.be.equal(2);
667-
server.respondWith("GET", newAuthEndpoint,
667+
server.respondWith("GET", new RegExp(newAuthEndpoint + ".*"),
668668
[
669669
200,
670670
{ "Content-Type": "application/json" },

0 commit comments

Comments
 (0)