uploadFile

Upload local resources to the cloud storage. If uploaded to the same path, it will be overwritten.

Request parameters

Field Description Data type Default Value Required
cloudPath Cloud storage path String - Y
fileContent Content of the file to upload fs.ReadStream - Y

Promise return result description

Field Description Data type
fileID File ID String
statusCode HTTP status code returned by server Number

Error return parameter

Field Description Data type
errCode Error code Number
errMsg Error message, in the format of apiName:fail msg String

Examples of uses

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