Browse API 1 documentation
GroveAPI 1preview

grove.composer.upload()

Hand one in-memory file to Mango's configured uploader.

Mango 3.1+View Markdown

Hand one in-memory file to Mango’s configured uploader.

Signature

ts
grove.composer.upload(data: Uint8Array | ArrayBuffer, options: { filename: string, caption?: string }): void

Availability

Exclusive composer surface with application scope and uploads.use. Network access used to obtain the bytes requires its own grants.

Parameters

Parameter Required Description
data Yes Nonempty Uint8Array or ArrayBuffer, at most 8 MiB (8,388,608 bytes). A Blob, File, URL, base64 string, or arbitrary typed array is not accepted.
options.filename Yes Nonempty suggested filename, at most 255 UTF-8 bytes. Native filename sanitation applies; it is not a filesystem path.
options.caption No Plain-text label before the uploaded URL, at most 160 UTF-8 bytes. Must be nonempty after trimming, contain no control characters or line breaks, and not start with /.

Return value

Returns undefined; the extension receives neither the upload URL nor provider credentials.

Behavior and errors

Missing filename or unsupported data type throws TypeError synchronously. Excessive filename length, zero-length data, or excessive bytes throws RangeError synchronously. Native scope/grant/filename validation can refuse the call after it returns. On acceptance Mango closes the utility, creates a temporary attachment, uses the current IRC session’s configured uploader, and inserts the resulting URL into the draft. Upload failures are handled by Mango’s native upload workflow.

With a caption, the inserted text is caption + " " + URL; without one it remains the bare URL. Invalid captions throw TypeError, oversized captions throw RangeError, and native validation checks them again. The caption is inserted only when that upload succeeds, together with its URL. It is not Markdown, an IRC command, an automatic send, or a URL template. Older hosts that support upload but not caption ignore the extra option and insert only the URL.

Example

js
try {
  const bytes = new TextEncoder().encode('A small generated attachment')
  grove.composer.upload(bytes, { filename: 'notes.txt' })
} catch {
  console.error('Could not submit the attachment.')
}

See grove.network.request() for bounded binary downloads.