Appearance
Function: convertArrayBufferToMwFile()
ts
function convertArrayBufferToMwFile(
arrayBuffer: ArrayBuffer,
name: string,
type: string): MwFile;Defined in: src/file/mwFile.ts:118
Experimental
Create an MwFile from an ArrayBuffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
arrayBuffer | ArrayBuffer | The raw binary data for the file. |
name | string | The file name, including extension. |
type | string | The MIME type of the file. |
Returns
An MwFile containing the buffer data and metadata.
Example
ts
const response = await fetch('https://example.com/cat-photo.jpg');
const buffer = await response.arrayBuffer();
const catPhoto = convertArrayBufferToMwFile(buffer, 'cat-photo.jpg', 'image/jpeg');
console.log(catPhoto.size); // file size in bytes