config.responseHeaders
option (passed intoFilesCollection
Constructor)
Allows to change default response headers.
We recommend to keep original function structure, with your modifications
function responseHeaders (responseCode, fileRef, versionRef) {
const headers = {};
switch (responseCode) {
case '206':
headers['Pragma'] = 'private';
headers['Transfer-Encoding'] = 'chunked';
break;
case '400':
headers['Cache-Control'] = 'no-cache';
break;
case '416':
headers['Content-Range'] = 'bytes */' + versionRef.size;
}
headers['Connection'] = 'keep-alive';
headers['Content-Type'] = versionRef.type || 'application/octet-stream';
headers['Accept-Ranges'] = 'bytes';
return headers;
}
We recommend to pass responseHeaders
as a Function, response headers should be conditional.
// As function (keep original function with additions):
const Uploads = new FilesCollection({
responseHeaders(responseCode, fileRef, versionRef, version, http) {
const headers = {};
switch (responseCode) {
case '206':
headers['Pragma'] = 'private';
headers['Transfer-Encoding'] = 'chunked';
break;
case '400':
headers['Cache-Control'] = 'no-cache';
break;
case '416':
headers['Content-Range'] = 'bytes */' + versionRef.size;
}
headers['Connection'] = 'keep-alive';
headers['Content-Type'] = versionRef.type || 'application/octet-stream';
headers['Accept-Ranges'] = 'bytes';
headers['Access-Control-Allow-Origin'] = '*';// <-- Custom header
return headers;
}
});
// As object (not recommended):
const Uploads = new FilesCollection({
responseHeaders: {
Connection: 'keep-alive',
'Access-Control-Allow-Origin': '*'
}
});