# 操作场景

本文档主要指导您如何通过文件存储在客户端(小程序端和web端)和服务端下载文件。

# 操作步骤

# 客户端

# 小程序端

示例代码如下:

wx.cloud
  .downloadFile({
    fileID: "" // 文件 ID
  })
  .then(res => {
    // 返回临时文件路径
    console.log(res.tempFilePath);
  })
  .catch(console.error);

# 网页端(Web 端)

由于跨域等原因,网页端暂时不支持下载文件。

# 服务端

示例代码如下:

const app = require("tcb-admin-node");
app.init();
app
  .downloadFile({
    fileID: "cloud://aa-99j9f/my-photo.png"
    // tempFilePath: '/tmp/test/storage/my-photo.png'
  })
  .then(res => {
    // 返回临时文件路径
    console.log(res.tempFilePath);
  })
  .catch(console.error);