📅  最后修改于: 2023-12-03 15:21:28.275000             🧑  作者: Mango
Blob 可以用于存储二进制数据,如图像、视频、音频等等。在 JavaScript 中,我们可以通过 Blob 对象来创建、读取和上传二进制数据。
以下是上传 Blob 的一般步骤:
const binaryData = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
const blob = new Blob([binaryData], { type: 'application/octet-stream' });
const uploadBlob = async (blob) => {
const url = 'https://example.com/upload';
const response = await fetch(url, { method: 'POST', body: blob });
const statusCode = response.status;
const result = await response.text();
return { statusCode, result };
};
const { statusCode, result } = await uploadBlob(blob);
console.log(statusCode, result);