The example implementations below may be helpful when performing certain API operations.
File Uploads
Consider using the following code examples when uploading files.
Generate the upload checksum
import { createSHA256 } from "hash-wasm";
export const generateSHA256Checksum = async (file: File) => {
const sha256 = await createSHA256();
const chunkSize = 10 * 1024 * 1024; // 10 MB
const fileSize = file.size;
for (let offset = 0; offset < fileSize; offset += chunkSize) {
const chunk = file.slice(offset, offset + chunkSize);
const buffer = await chunk.arrayBuffer();
sha256.update(new Uint8Array(buffer));
}
const hashBuffer = sha256.digest("binary");
return btoa(String.fromCharCode.apply(null, Array.from(hashBuffer)));
}import hashlib
import base64
from pathlib import Path
def generate_sha256_checksum(file_path: Path) -> str:
with file_path.open("rb") as f:
hash_digest = hashlib.file_digest(f, "sha256").digest()
return base64.b64encode(hash_digest).decode('utf-8')Encode the file name
const encodedFileName = encodeURIComponent("file_name123%€.wav")import urllib.parse
encoded_file_name = urllib.parse.quote("file_name123%€.wav", safe="-.!~*'()")