# uploadFile

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

Request parameters

Field Description Data Type Default Required
cloudPath Cloud storage path. For naming rules, see File Naming Rules String - Y
fileContent Content of the file to upload Buffer or fs.ReadStream - Y

Description of Promise return result

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

Error return parameter

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

# Use Case

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