Skip to main content

Overview

The NTQQFileApi class provides methods for uploading, downloading, and managing files, including images, videos, audio, and documents.

File Upload

uploadFile

Upload a file and get its metadata.
string
required
Path to file to upload
ElementType
default:"ElementType.PIC"
Type of element (PIC, VIDEO, PTT, FILE, etc.)
number
default:"0"
Element subtype
boolean
default:"true"
Whether to upload as group file
object
Object containing file metadata:
  • md5: File MD5 hash
  • fileName: File name
  • path: File path
  • fileSize: File size in bytes
  • ext: File extension
Example:

File Download

downloadMedia

Download media from a message.
string
required
Message ID containing the media
ChatType
required
Chat type (group/private)
string
required
Peer UID
string
required
Element ID of the media
string
required
Thumbnail path
string
required
Source file path
number
default:"120000"
Download timeout in milliseconds
boolean
default:"false"
Force re-download even if file exists
string
Path to downloaded file
Example:

downloadRawMsgMedia

Download all media elements from raw messages.
RawMessage[]
required
Array of raw messages
string[]
Array of file paths to downloaded media
Example:

downloadFileForModelId

Download file using model ID.
Peer
required
Peer object
string
required
File model ID
string
required
Additional parameter
number
default:"120000"
Timeout in milliseconds
string
Downloaded file path

downloadFileById

Download file by file ID.
string
required
File ID to download
number
default:"1024576"
Expected file size in bytes
number
Estimated download time in milliseconds (auto-calculated)
string
Downloaded file path

File URLs

getFileUrl

Get download URL for a file.
ChatType
required
Chat type (group/private)
string
required
Peer ID
string
File UUID
string
File MD5 (for files < 10MB)
number
default:"5000"
Request timeout in milliseconds
string
File download URL
Example:

getPttUrl

Get download URL for voice/audio file.
string
required
Peer ID
string
File UUID
number
default:"5000"
Request timeout
string
PTT (voice) file URL

getVideoUrl

Get playback URL for video.
Peer
required
Peer object
string
required
Message ID
string
required
Video element ID
string
Video playback URL

getVideoUrlPacket

Get video URL using packet API.
string
required
Peer ID
string
File UUID
number
default:"5000"
Request timeout

Image URLs

getImageUrl

Get image URL from picture element.
PicElement
required
Picture element from message
string
Image URL
Example:

searchForFile

Search for files by keywords.
string[]
required
Array of search keywords
SearchResultItem | undefined
First matching search result
Example:

File Utilities

copyFile

Copy a file to another location.
string
required
Source file path
string
required
Destination file path

getFileSize

Get size of a file.
string
required
Path to file
number
File size in bytes
Example:

Complete Example: File Upload and Download

Notes

  • File operations may have size limits imposed by QQ servers
  • Large file downloads should use appropriate timeout values
  • The RKey (resource key) is automatically managed for file URLs
  • Some file operations require packet API to be enabled
  • Downloaded files are typically stored in NTQQ’s cache directory