# API Guidelines

# Uploading Files

In the Mini Program, call wx.cloud.uploadFile to upload files:

wx.cloud.uploadFile({
  cloudPath: 'example.png', // Cloud path for upload
  filePath: '', // Temporary file path in the Mini Program
  success: res => {
    // File ID is returned
    console.log(res.fileID)
  },
  fail: console.error
})

After a successful upload, a unique file identifier, i.e., file ID, is returned. All operations performed later on will use the file ID not URL.

# Downloading Files

Use file ID to download files. Users can only download files that they have access to:

wx.cloud.downloadFile({
  fileID: '', // File ID
  success: res => {
    // Temporary file path is returned
    console.log(res.tempFilePath)
  },
  fail: console.error
})

# Deleting Files

Use wx.cloud.deleteFile to delete files:

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

For more APIs, refer to the Mini Program and backend storage API documentation.

# Supported Components

You can import cloud file ID in image and audio components. For details, refer to documentation.

Use file ID to obtain a temporary file link, which is valid for two hours:

wx.cloud.getTempFileURL({
  fileList: ['cloud://xxx.png'],
  success: res => {
    // fileList is an object array with the following structure
    // [{
    //    fileID: 'cloud://xxx.png', // File ID
    //    tempFileURL: '', // Temporary file link
    //    maxAge: 120 * 60 * 1000, // Validity period
    // }]
    console.log(res.fileList)
  },
  fail: console.error
})

# API Documentation

For details, refer to Mini Program storage API documentation and Server API documentation.