You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-77Lines changed: 48 additions & 77 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1129,99 +1129,70 @@ When you exceed the rate limits for an endpoint, you will receive a `429` status
1129
1129
1130
1130
ImageKit sends `x-ik-signature` in the webhook request header, which can be used to verify the authenticity of the webhook request.
1131
1131
1132
-
Verifing webhook signature is easy with imagekit SDK. All you need is `x-ik-signature`, rawRequestBody and secretKey. You can copy webhook secret from imagekit dashboard.
1132
+
Verifying webhook signature is easy with imagekit SDK. All you need is the value of the `x-ik-signature` header, request body, and [webhook secret](https://imagekit.io/dashboard/developer/webhooks) from the ImageKit dashboard.
1133
1133
1134
-
```js
1135
-
try {
1136
-
const {
1137
-
timestamp, // Unix timestamp in milliseconds
1138
-
event, // Parsed webhook event object
1139
-
} =imagekit.verifyWebhookEvent(
1140
-
'{"type":"video.transformation.accepted","id":"58e6d24d-6098-4319-be8d-40c3cb0a402d"...', // Raw request body encoded as Uint8Array or UTF8 string
// It is triggered when a new video transformation request is accepted for processing. You can use this for debugging purposes.
1202
-
break;
1203
-
case'video.transformation.ready':
1204
-
// It is triggered when a video encoding is finished and the transformed resource is ready to be served. You should listen to this webhook and update any flag in your database or CMS against that particular asset so your application can start showing it to users.
1205
-
break;
1206
-
case'video.transformation.error':
1207
-
// It is triggered if an error occurs during encoding. Listen to this webhook to log the reason. You should check your origin and URL-endpoint settings if the reason is related to download failure. If the reason seems like an error on the ImageKit side, then raise a support ticket at [email protected].
1208
-
break;
1209
-
// ... handle other event types
1210
-
default:
1211
-
console.log(`Unhandled event type ${event.type}`);
1212
-
}
1213
-
1214
-
// Acknowledge webhook is received and processed successfully
if (timestamp +WEBHOOK_EXPIRY_DURATION<Date.now()) {
1169
+
// Return a response to acknowledge receipt of the event so that ImageKit doesn't retry sending this webhook.
1170
+
res.send()
1171
+
}
1172
+
1173
+
// Handle webhook
1174
+
switch (event.type) {
1175
+
case'video.transformation.accepted':
1176
+
// It is triggered when a new video transformation request is accepted for processing. You can use this for debugging purposes.
1177
+
break;
1178
+
case'video.transformation.ready':
1179
+
// It is triggered when a video encoding is finished, and the transformed resource is ready to be served. You should listen to this webhook and update any flag in your database or CMS against that particular asset so your application can start showing it to users.
1180
+
break;
1181
+
case'video.transformation.error':
1182
+
// It is triggered if an error occurs during encoding. Listen to this webhook to log the reason. You should check your origin and URL-endpoint settings if the reason is related to download failure. If the reason seems like an error on the ImageKit side, then raise a support ticket at [email protected].
1183
+
break;
1184
+
default:
1185
+
// ... handle other event types
1186
+
console.log(`Unhandled event type ${event.type}`);
1187
+
}
1188
+
1189
+
// Return a response to acknowledge receipt of the event
0 commit comments