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

Upload

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

uploadFile

This API is used via UploadTask wx.uploadFile(Object object).
Feature Description: Uploads local resources to the server. The client initiates an HTTPS POST request, where the content-type is multipart/form-data. Prior to usage, read relevant instructions.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
url
string
-
Yes
Developer Server Address
filePath
string
-
Yes
Path to the file resource to be uploaded (local path)
name
string
-
Yes
The corresponding key for the file, through which developers can access the binary content of the file on the server side.
header
object
-
No
HTTP request's Header; setting Referer within the Header is not allowed.
formData
object
-
No
Additional form data in the HTTP request
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Parameters for object.success callback function: Object res.
Attribute
Type
Description
data
string
Data returned from the developer's server.
statusCode
number
HTTP status code returned from the developer's server.
Return Value: UploadTask, an object that can monitor the progress of the upload and cancel the upload.
Sample Code
wx.chooseImage({
success (res){
const tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: 'https://example.weixin.qq.com/upload', // This is merely an example and not an actual interface address.
filePath: tempFilePaths[0],
name: 'file',
formData:{
'user': 'test'
},
success (res){
const data = res.data
//do something
}
})
}
})

UploadTask

.abort

This method is used via UploadTask.abort().
Feature Description: Aborts the upload task.

.onProgressUpdate

This method is used via UploadTask.onProgressUpdate(function listener).
Feature Description: Monitors upload progress change events.
Parameter and Description: function listener, listener for upload progress change events, arguments Object.res are as follows.
Attribute
Type
Description
progress
number
Download progress percentage
totalBytesWritten
number
Length of the data already downloaded, measured in Bytes.
totalBytesExpectedToWrite
number
Total length of the data expected to be downloaded, measured in bytes.

.offProgressUpdate

This method is used via UploadTask.offProgressUpdate(function listener).
Feature Description: Removes the listener function for upload progress change events.
Parameters and Description: function listener, the listener function passed in by onProgressUpdate. If this parameter is not passed in, all listener functions will be removed.
Sample Code
const listener = function (res) { console.log(res) }

DownloadTask.onProgressUpdate(listener)
DownloadTask.offProgressUpdate(listener) // The same function object as the listener must be passed in.

.onHeadersReceived

This method is used via UploadTask.onHeadersReceived(function listener).
Feature Description: Monitors HTTP Response Header events. This occurs earlier than the request completion event.
Parameter and Description: function listener, the listener function for HTTP Response Header events.
Attribute
Type
Description
header
Object
HTTP Response Header returned from the developer's server.

.offHeadersReceived

This method is used via UploadTask.offHeadersReceived(function listener).
Feature Description: Removes the listener function for HTTP Response Header events.
Parameters and Description: function listener, the listener function passed in by onHeadersReceived. If this parameter is not passed in, all listener functions will be removed.
Sample Code
const listener = function (res) { console.log(res) }

UploadTask.onHeadersReceived(listener)
UploadTask.offHeadersReceived(listener) // The same function object as the listener must be passed in.

Sample code

const uploadTask = wx.uploadFile({
url: 'http://example.weixin.qq.com/upload', // This is merely an example and not an actual interface address.
filePath: tempFilePaths[0],
name: 'file',
formData:{
'user': 'test'
},
success (res){
const data = res.data
//do something
}
})

uploadTask.onProgressUpdate((res) => {
console.log('Upload progress', res.progress)
console.log('Length of already uploaded data', res.totalBytesSent)
console.log('Total length of data expected to be uploaded', res.totalBytesExpectedToSend)
})

uploadTask.abort() // Aborts upload task



Help and Support

Was this page helpful?

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

Feedback