This example shows how to add custom HTTP headers to image uploads with a custom image.upload handler.
<div id="entry-upload-headers"></div>
const app = Redactor('#entry-upload-headers', {
image: {
upload(uploader, { data, files, e }) {
fetch('/api/endpoint/upload-image/', {
method: 'POST',
headers: {
'X-Demo-Token': 'demo-token'
},
body: data
})
.then((res) => res.json())
.then((json) => uploader.complete(json, e))
.catch((err) => uploader.complete({ error: true, message: String(err) }, e));
}
}
});