GramIO API Reference / @gramio/files/dist / MediaUpload
Class: MediaUpload
Defined in: files/index.d.ts:88
Class-helper with static methods for file uploading.
Constructors
Constructor
new MediaUpload():
MediaUpload
Returns
MediaUpload
Methods
buffer()
staticbuffer(buffer,filename?):File
Defined in: files/index.d.ts:118
Method for uploading Media File by BinaryLike (Buffer or ArrayBuffer and etc).
Parameters
| Parameter | Type |
|---|---|
buffer | any |
filename? | string |
Returns
File
localPath()
staticlocalPath(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
| Parameter | Type |
|---|---|
path | string |
Returns
string
Example
// file already on the server's disk → no HTTP upload of the bytes
ctx.sendDocument(MediaUpload.localPath("/var/data/big-archive.zip"));path()
staticpath(path,filename?):Promise<File>
Defined in: files/index.d.ts:92
Method for uploading Media File by local path.
Parameters
| Parameter | Type |
|---|---|
path | string |
filename? | string |
Returns
Promise<File>
stream()
staticstream(stream,filename?):Promise<File>
Defined in: files/index.d.ts:114
Method for uploading Media File by Readable stream.
Parameters
| Parameter | Type |
|---|---|
stream | Readable | ReadableStream<any> |
filename? | string |
Returns
Promise<File>
text()
statictext(text,filename?):File
Defined in: files/index.d.ts:126
Method for uploading Media File by text content.
Parameters
| Parameter | Type |
|---|---|
text | string |
filename? | string |
Returns
File
url()
staticurl(url,filename?,options?):Promise<File>
Defined in: files/index.d.ts:122
Method for uploading Media File by URL (also with fetch options).
Parameters
| Parameter | Type |
|---|---|
url | string | URL |
filename? | string |
options? | RequestInit |
Returns
Promise<File>