Skip to content

GramIO API Reference / @gramio/files/dist / MediaUpload

Class: MediaUpload

Defined in: files/index.d.ts:88

Class-helper with static methods for file uploading.

Documentation

Constructors

Constructor

new MediaUpload(): MediaUpload

Returns

MediaUpload

Methods

buffer()

static buffer(buffer, filename?): File

Defined in: files/index.d.ts:118

Method for uploading Media File by BinaryLike (Buffer or ArrayBuffer and etc).

Parameters

ParameterType
bufferany
filename?string

Returns

File


localPath()

static localPath(path): string

Defined in: files/index.d.ts:110

Reference a file by its local path on a self-hosted Bot API server (--local mode) using the file:// URI scheme. The server reads the file straight from its own disk, so the bytes are never transferred over HTTP.

This is an optimization, not a requirement for large files: a local Bot API server already accepts up to 2 GB via a normal upload (MediaUpload.path / MediaUpload.stream). Use localPath only when the file already lives on the Bot API server's filesystem (bot co-located, or a shared volume) to skip re-uploading it.

Parameters

ParameterType
pathstring

Returns

string

Example

ts
// file already on the server's disk → no HTTP upload of the bytes
ctx.sendDocument(MediaUpload.localPath("/var/data/big-archive.zip"));

path()

static path(path, filename?): Promise<File>

Defined in: files/index.d.ts:92

Method for uploading Media File by local path.

Parameters

ParameterType
pathstring
filename?string

Returns

Promise<File>


stream()

static stream(stream, filename?): Promise<File>

Defined in: files/index.d.ts:114

Method for uploading Media File by Readable stream.

Parameters

ParameterType
streamReadable | ReadableStream<any>
filename?string

Returns

Promise<File>


text()

static text(text, filename?): File

Defined in: files/index.d.ts:126

Method for uploading Media File by text content.

Parameters

ParameterType
textstring
filename?string

Returns

File


url()

static url(url, filename?, options?): Promise<File>

Defined in: files/index.d.ts:122

Method for uploading Media File by URL (also with fetch options).

Parameters

ParameterType
urlstring | URL
filename?string
options?RequestInit

Returns

Promise<File>