tencent cloud

Tencent Cloud Super App as a Service

Release Notes and Announcements
Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
Product Introduction
Overview
Strengths
Use Cases
Purchase Guide
Billing Overview
Pay-As-You-Go Billing
Renewal Guide
Service Suspension Instructions
Getting Started
Plan Management
Overview
Console Account Management
Storage Configuration
Acceleration Configuration
Branding Configurations
Platform Features
Console Login
Users and Permission System
Mini Program Management
Mini Game Management
Superapp Management
Commercialization
Platform Management
User Management
Team Management
Operations Management
Security Center
Code Integration Guide
Getting Demo and SDK
Android
iOS
Flutter
Superapp Server
GUID Generation Rules
Mini Program Development Guide
Mini Program Introduction and Development Environment
Mini Program Code Composition
Guide
Framework
Components
API
Server Backend
JS SDK
Base Library
IDE Operation Instructions
Mini Game Development Guide
Guide
API
Server Backend
Practice Tutorial
Mini Program Login Practical Tutorial
Mini Program Subscription Message Practical Tutorial
Payment Practical Tutorial
Ad Integration Practical Tutorial
Mini Game Subscription Message Practical Tutorial
API Documentation
History
Introduction
API Category
Making API Requests
Operation Management APIs
User Management APIs
Team Management APIs
Sensitive API-Related APIs
Role Management APIs
Platform Management APIs
Other Console APIs
Mini Program or Mini Game APIs
Management-Sensitive APIs
Global Domain Management APIs
Superapp APIs
Data Types
Agreements
Service Level Agreement
Data Processing and Security Agreement
SDK Privacy Policy Module
SDK Data Processing and Security Agreement Module

Download

PDF
Focus Mode
Font Size
Last updated: 2025-04-10 18:18:33

downloadFile

This API is called using DownloadTask wx.downloadFile(Object object).
Note:
Please specify a reasonable Content-Type field in the server response header to ensure that the client processes the file type correctly.
Feature description:Downloads a file resource to the local device. The client initiates an HTTPS GET request, with the local temporary path (local path) of the file returned. The maximum file size allowed for a single download is 200 MB. Before calling this API, please read Network.
Parameter and description:Object object.
Property
Type
‍Required
Description
url
string
True
The URL of the resource to download.
header
Object
False
HTTP request header. The Referer cannot be set in the header.
filePath
string
False
The path where the downloaded file will be stored.
success
function
False
Callback function for successful API calls.
fail
function
False
Callback function for failed API calls.
complete
function
False
Callback function executed after API call ends (regardless of success or failure).
object.success callback function parameter:Object res.
Property
Type
Description
tempFilePath
string
Temporary file path (local path). Returned if filePath is not specified. The downloaded file will be stored in a temporary file
filePath
string
User file path (local path). Returned if filePath is specified and will match the provided filePath.
statusCode
number
The HTTP status code returned by the developer’s server.
Return value:DownloadTask
Example:
wx.downloadFile({
url: 'https://example.com/audio/123', // Example URL, not a real resource
success (res) {
// As long as the server responds, the response content will be written to the file and the success callback will be triggered. You need to determine if the desired content was downloaded
if (res.statusCode === 200) {
console.log('filePath', res.tempFilePath);
}
}
})

DownloadTask

.abort

This method is called using DownloadTask.abort().
Feature description:Aborts the download task.

.onProgressUpdate

This method is called using DownloadTask.onProgressUpdate(function listener).
Feature description:Listens for download progress change event.
Parameter and description:function listener. The listener for download progress change event.
Property
Type
Description
progress
number
Download progress percentage.
totalBytesWritten
number
The length of data that has been downloaded, in bytes.
totalBytesExpectedToWrite
number
The total length of data expected to be downloaded, in bytes.

.offProgressUpdate

This method is called using DownloadTask.offProgressUpdate(function listener).
Feature description:Removes the listener for download progress change event.
Parameter and description:function listener. The listener passed to onProgressUpdate. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

DownloadTask.onHeadersReceived(listener)
DownloadTask.offHeadersReceived(listener) // Must pass the same function object used in onHeadersReceived

.onHeadersReceived

This method is called using DownloadTask.onHeadersReceived(function listener).
Feature description:Listens for the HTTP Response Header event. The event is triggered before the response is received.
Parameter and description:function listener. The listener for the HTTP Response Header event.
Property
Type
Description
header
Object
The HTTP response header returned by the developer’s server.

.offHeadersReceived

This method is called using DownloadTask.offHeadersReceived(function listener).
Feature description:Removes the listener for the HTTP Response Header event.
Parameter and description:function listener. The listener passed to onHeadersReceived. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

DownloadTask.onHeadersReceived(listener)
DownloadTask.offHeadersReceived(listener) // Must pass the same function object used in onHeadersReceived

Example

const downloadTask = wx.downloadFile({
url: 'http://example.com/audio/123', // Example URL, not a real resource
success (res) {
wx.playVoice({
filePath: res.tempFilePath
})
}
})

downloadTask.onProgressUpdate((res) => {
console.log ('Download progress', res.progress)
console.log (' Length of the downloaded data', res.totalBytesWritten)
console.log ('Expected total length of the data to be downloaded', res.totalBytesExpectedToWrite)
})

DownloadTask.abort () // Cancel the download task



Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback