FBlob
Access
Access through:
Setup
Register @univerjs/core or a preset that includes it. In plugin mode, import @univerjs/core/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs/core
FBlob.copyBlob
Returns a copy of this blob.
copyBlob(): FBlobReturns
a new blob by copying the current blob
Examples
const blob = univerAPI.newBlob()const newBlob = blob.copyBlob()console.log(newBlob)Types: FBlob
Package: @univerjs/core · Type definitions
FBlob.getAs
Returns a copy labeled with the specified MIME type. The data bytes are not converted or re-encoded.
getAs(contentType: string): FBlobParameters
contentType— Required. the content type refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types
Returns
A new facade containing the same data with the specified MIME type.
Examples
const blob = univerAPI.newBlob()const newBlob = blob.getAs('text/plain')console.log(newBlob)Types: FBlob
Package: @univerjs/core · Type definitions
FBlob.getBytes
Gets the data stored in this blob.
getBytes(): Promise<Uint8Array>Returns
A promise resolving to the bytes; rejects if no blob data is set.
Examples
const blob = univerAPI.newBlob().setDataFromString('Hello, World!')const bytes = await blob.getBytes()console.log(bytes)Types: Uint8Array · Promise
Package: @univerjs/core · Type definitions
FBlob.getContentType
Gets the content type of the data stored in this blob.
getContentType(): string | undefinedReturns
The MIME type, or undefined if no blob data is set.
Examples
const blob = univerAPI.newBlob()const contentType = blob.getContentType()console.log(contentType)Package: @univerjs/core · Type definitions
FBlob.getDataAsString
Get the blob as a string.
getDataAsString(): Promise<string>getDataAsString(charset?: string): Promise<string>Parameters
charset— Optional. TextDecoder encoding label. Defaults to UTF-8.
Returns
A promise resolving to decoded text; an unset blob returns an empty string.
Examples
const blob = univerAPI.newBlob()const data = await blob.getDataAsString()console.log(data)const blob = univerAPI.newBlob()const data = await blob.getDataAsString('iso-8859-1')console.log(data)Types: Promise
Package: @univerjs/core · Type definitions
FBlob.setBytes
Sets the data stored in this blob.
setBytes(bytes: Uint8Array): FBlobParameters
bytes— Required. a byte array
Returns
the blob object
Examples
const blob = univerAPI.newBlob()const bytes = new Uint8Array(10)blob.setBytes(bytes)Types: FBlob · Uint8Array
Package: @univerjs/core · Type definitions
FBlob.setContentType
Sets the MIME type without converting or re-encoding the data bytes. Has no effect when no blob data is set.
setContentType(contentType: string): FBlobParameters
contentType— Required. the content type refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types
Returns
the blob object
Examples
const blob = univerAPI.newBlob()blob.setContentType('text/plain')Types: FBlob
Package: @univerjs/core · Type definitions
FBlob.setDataFromString
Sets the data stored in this blob.
setDataFromString(data: string): FBlobsetDataFromString(data: string, contentType?: string): FBlobParameters
data— Required. blob data stringcontentType— Optional. the content type refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types
Returns
the blob object
Examples
const blob = univerAPI.newBlob()blob.setDataFromString('Hello, World!')const blob = univerAPI.newBlob()blob.setDataFromString('Hello, World!', 'text/plain')Types: FBlob
Package: @univerjs/core · Type definitions
How is this guide?