The checksum attribute is a Base64 version of your file MD5. Here's a TypeScript sample of how mounting those files in a browser will look like.
const convertFileToMd5 = (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = function (event) {
const binary = event.target?.result;
if (binary) {
const wordArray = enc.Latin1.parse(binary as string);
const md5 = MD5(wordArray).toString();
resolve(md5);
} else {
reject(new Error('Failed to read file'));
}
};
reader.onerror = function (error) {
reject(error);
};
reader.readAsBinaryString(file);
});
};
const mountFileToSend = (file: File, md5: string) => {
const base64 = btoa(
md5
.match(/\w{2}/g)!
.map((a) => String.fromCharCode(parseInt(a, 16)))
.join('')
);
return {
key: '',
filename: file.name,
byte_size: file.size,
checksum: base64,
content_type: file.type,
size: file.size,
};
};
// usage
const md5 = await convertFileToMd5(file);
// this is what will be sent to the API
const fileData = mountFileToSend(file, md5);
Response
The important key here is direct_upload, that's where the signed url that the file will be sent to is, it's also the place where the headers live, those will also be sent to the same URL as part of the PUT request.
here's an example on how the request would look like in TypeScript.
fetch(direct_upload.url, {
method: 'PUT',
headers: direct_upload.headers as Record<
string,
string
>,
// the same file we generated the MD5 from, you can send the File itself
body: file,
});