Skip to content
Open
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
27 changes: 24 additions & 3 deletions client/vanillajs/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'regenerator-runtime/runtime'

import Uppy from '@uppy/core'
import '@uppy/core/dist/style.css'
import '@uppy/dashboard/dist/style.css'
Expand All @@ -13,6 +15,25 @@ import '@uppy/webcam/dist/style.css'
const SERVER_BASE_URL = window.SERVER_BASE_URL;
const IMAGEKIT_PUBLIC_KEY = window.IMAGEKIT_PUBLIC_KEY;

const authenticator = async () => {
try {

// You can pass headers as well and later validate the request source in the backend, or you can use headers for any other use case.
const response = await fetch(`${SERVER_BASE_URL}/auth`);

if (!response.ok) {
const errorText = await response.text();
throw new Error(`Request failed with status ${response.status}: ${errorText}`);
}

const data = await response.json();
const { signature, expire, token } = data;
return { signature, expire, token };
} catch (error) {
throw new Error(`Authentication request failed: ${error.message}`);
}
};

const metaFields = [
{
id: 'name', name: 'File name', placeholder: 'Enter the file name'
Expand Down Expand Up @@ -61,8 +82,8 @@ const uppy = Uppy({ debug: true, autoProceed: false })
inline: true,
trigger: '#uppyDashboard',
metaFields: metaFields,
proudlyDisplayPoweredByUppy : false,
note : "ImageKit Uppy Sample • https://github.com/imagekit-samples/uppy-uploader"
proudlyDisplayPoweredByUppy: false,
note: "ImageKit Uppy Sample • https://github.com/imagekit-samples/uppy-uploader"
})
.use(GoogleDrive, { target: Dashboard, companionUrl: SERVER_BASE_URL }) // don't add trailing slash
.use(Dropbox, { target: Dashboard, companionUrl: SERVER_BASE_URL })
Expand All @@ -71,8 +92,8 @@ const uppy = Uppy({ debug: true, autoProceed: false })
.use(Url, { target: Dashboard, companionUrl: SERVER_BASE_URL })
.use(ImageKitUppyPlugin, {
id: 'ImageKit',
authenticationEndpoint: `${SERVER_BASE_URL}/auth`,
publicKey: IMAGEKIT_PUBLIC_KEY,
authenticator,
metaFields: [
"useUniqueFileName",
"tags",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"express": "^4.17.1",
"express-session": "^1.17.1",
"imagekit": "^3.0.5",
"imagekit-uppy-plugin": "1.0.0-beta.1",
"imagekit-uppy-plugin": "^2.0.0",
"path": "^0.12.7"
},
"devDependencies": {
Expand Down