Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

The WeChat Small Program Cloud Development Service Store API uploads on-premises resources to the cloud storage space


May 20, 2021 WeChat Mini Program Development Document


Table of contents


uploadFile

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

Use the example

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,
  })
}