filepond
filepond copied to clipboard
Added capabilities to have async header functions
A big part of uploading is to validate that the data doesn't get corrupted. One way to do it is to do a checksum and send it to the server as a part of the headers. Most checksum functions are asynchronous and this change would allow these types of functions to be added to the Filepond headers.
Example:
const server = {
url: '/api/http-upload/chunk',
patch: {
headers: async (chunk) => {
const { data, file, offset } = chunk;
const md5 = async () => await hashwasm.md5(new Uint8Array(await data.arrayBuffer()));
return {
'Content-Type': 'application/offset+octet-stream',
'Upload-Offset': offset,
'Upload-Length': file.size,
'Upload-Name': file.name,
'x-checksum-md5': await md5()
};
}
}
};
Excellent idea.
Can you move these outside of the Promise, I guess we can set them before applying the headers.
// set type of response
if (options.responseType) {
xhr.responseType = options.responseType;
}
// set credentials
if (options.withCredentials) {
xhr.withCredentials = true;
}