May 20, 2021 WeChat Mini Program Development Document
Upload on-premises resources to cloud storage, which is overwritten if uploaded to the same path.
Request parameters
Field | Description | The data type | The default | Required |
---|---|---|---|---|
cloudPath | Cloud storage path | String | - | Y |
fileContent | The contents of the file to upload | Fs. ReadStream | - | Y |
Promise returns the result description
Field | Description | The data type |
---|---|---|
fileID | File ID | String |
statusCode | The HTTP status code returned by the server | Number |
The argument was returned incorrectly
Field | Description | The data type |
---|---|---|
errCode | Error code | Number |
errMsg | Error message, format apiName:fail msg | String |
Promise style
const cloud = require('wx-server-sdk')
const fs = require('fs')
const path = require('path')
exports.main = async (event, context) => {
const fileStream = fs.createReadStream(path.join(__dirname, 'demo.jpg'))
return await cloud.uploadFile({
cloudPath: 'demo.jpg',
fileContent: fileStream,
})
}