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

WeChat small program cloud development storage


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Cloud storage provides highly available, stable, and secure cloud storage services that support any number and form of unstructured data storage, such as video and pictures, and visual management in the console. Cloud storage includes the following features:

  • Storage management: Supports folders for file classifying. Support file upload, delete, move, download, search, etc., and you can view the details of the file
  • Permission settings: You have the flexibility to set which users can read and write files in the folder to keep your business data secure
  • Upload management: Here you can view file upload history, progress, and status
  • File search: Supports the search for file prefix names and subdirect directory files
  • Component support: Supports the incoming cloud file ID in components such as image and audio

Next, let's look at what APIs cloud file management provides and how to manage cloud files in the console:

  • Store the API
  • Manage files in the console

API guidelines

Upload the file

The wx.cloud.uploadFile method can be called on the small terminal to upload:

wx.cloud.uploadFile({
  cloudPath: 'example.png', // 上传至云端的路径
  filePath: '', // 小程序临时文件路径
  success: res => {
    // 返回文件 ID
    console.log(res.fileID)
  },
  fail: console.error
})

When the upload is successful, you get a unique identifier for the file, the file ID, and subsequent actions are based on the file ID rather than the URL.

Download the file

Files can be downloaded based on the file ID, and users can only download files that they have access to:

wx.cloud.downloadFile({
  fileID: '', // 文件 ID
  success: res => {
    // 返回临时文件路径
    console.log(res.tempFilePath)
  },
  fail: console.error
})

Delete the file

You can delete the file by wx.cloud.deleteFile:

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

A more detailed API can refer to the smaller and back-end storage API files.

Component support

Support in components such as Image, Audio, etc., for specific support lists Documentation

Exchange temporary links

You can exchange the temporary file network link according to the file ID, the file link is valid for two hours:

wx.cloud.getTempFileURL({
  fileList: ['cloud://xxx.png'],
  success: res => {
    // fileList 是一个有如下结构的对象数组
    // [{
    //    fileID: 'cloud://xxx.png', // 文件 ID
    //    tempFileURL: '', // 临时文件网络链接
    //    maxAge: 120 * 60 * 1000, // 有效期
    // }]
    console.log(res.fileList)
  },
  fail: console.error
})

API documentation

You can refer here to the detailed small terminal storage API documentation and the service side API documentation


Manage files

In the console, select the Storage Management tab, where you can see all the files in the cloud storage space, and you can view the details of the files and control the read and write rights to the storage space.



File name naming restrictions

  • Cannot be empty
  • Cannot start with/
  • No continuity/
  • The encoding length is up to 850 bytes
  • It is recommended to use english letters and numbers in case, i.e. a-z, A-Z, 0-9, and the symbols -,!,, ,.,, and their combinations
  • ASCII control characters are not supported on (s), under character (s), right (→), character left (←), corresponding to CAN (24), EM (25), SUB (26), ESC (27)
  • If a user uploads a file or folder with a Chinese name, when accessing and requesting the file or folder, the Chinese section is converted to a percent sign code according to the URL Encode rule.
  • Special characters are not recommended: ''
  • Special characters that may need special handling before they are used: , : ; The character range of 00-1F hex (0-31 hex) and 7F (127-dex)

Component support

The gadget component supports the incoming cloud file ID, and the list of support is as follows:

Component Property
image Src
video src、poster
cover-image Src
Interface Parameters
getBackgroundAudioManager Src
createInnerAudioContext Src
previewImage urls、current