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

WeChat small program cloud development SDK document file storage and deletion of files


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Cloud.deleteFile(fileList: string[]): Promise<Object>

Support: small programs, cloud functions, web

Delete files from cloud storage up to 50 at a time

Parameters

fileList: string[]

An array of cloud file ID strings

Returns a value

Promise.<Object>

Property Type Description
fileList Object The list of files

The structure of fileList

Property Type Description
fileID string Cloud file ID
status number Status code, 0 is successful
errMsg string Success is ok and failure is the cause of failure

Example of a small terminal

Promise style

wx.cloud.deleteFile({
  fileList: ['a7xzcb']
}).then(res => {
  // handle success
  console.log(res.fileList)
}).catch(error => {
  // handle error
})

Callback style

wx.cloud.deleteFile({
  fileList: ['a7xzcb'],
  success: res => {
    // handle success
    console.log(res.fileList)
  },
  fail: err => {
    // handle error
  },
  complete: res => {
    // ...
  }
})

An example of the cloud function side

const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

exports.main = async (event, context) => {
  const fileIDs = ['xxx', 'xxx']
  const result = await cloud.deleteFile({
    fileList: fileIDs,
  })
  return result.fileList
}