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

WeChat small program cloud development SDK document file storage in exchange for real links


May 20, 2021 WeChat Mini Program Development Document


Table of contents


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

Support: small programs, cloud functions, web

In exchange for a real link with a cloud file ID, the link obtained by the publicly read file does not expire, and the link obtained by the private file is valid for ten minutes. Take up to 50 at a time.

Parameters

fileList: string[]

The list of cloud file IDs to exchange for temporary links

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
tempFileURL string Temporary file path
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.getTempFileURL({
  fileList: [{
    fileID: 'a7xzcb',
    maxAge: 60 * 60, // one hour
  }]
}).then(res => {
  // get temp file URL
  console.log(res.fileList)
}).catch(error => {
  // handle error
})

Callback style

wx.cloud.getTempFileURL({
  fileList: ['cloud://xxx', 'cloud://yyy'],
  success: res => {
    // get temp file URL
    console.log(res.fileList)
  },
  fail: err => {
    // handle error
  }
})

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 fileList = ['cloud://xxx', 'cloud://yyy']
  const result = await cloud.getTempFileURL({
    fileList: fileList,
  })
  return result.fileList
}