AttachmentsApi.add()
Embed a file; it is in every save and export from then on. An index shifts down when an earlier attachment is deleted. Needs the
edit-pages feature.methodEditingsince 1.0.0
Signature
add(name: string, bytes: Uint8Array, options?: SignedDocumentOptions): Promise<number>
Parameters
| Parameter | Type | Description |
|---|---|---|
| name | string | The file name to store. |
| bytes | Uint8Array | The file's bytes. |
| options? | SignedDocumentOptions | { invalidateSignatures? }. |
Returns
Promise<number> Its index in list() (zero-based: its position in the document's table), for data() / delete().
Throws
INVALID_ARGUMENT— an emptyname.PAGE_ERROR— the file could not be embedded.FEATURE_NOT_LICENSED— the license lacksedit-pages.DOCUMENT_CLOSED— the document has been closed.INVALID_STATE— a certified document, unlessoptions.invalidateSignatures; or a progressive document still downloading.
Example
TypeScript
const index = await doc.attachments.add('invoice.csv', csvBytes);