产品概述
功能和优势
应用场景
系统限制
//第一步,引入 Web SDK,import tcb from "@cloudbase/js-sdk";//第二步,初始化const app = tcb.init({env: "your-env-id"});/**第三步,登录鉴权流程,此处代码略,请参考:https://www.tencentcloud.com/document/product/876/41728?from_cn_redirect=1*/app.uploadFile({// 云存储的路径cloudPath: "dirname/filename",// 需要上传的文件,File 类型filePath: document.getElementById("file").files[0]}).then((res) => {// 返回文件 IDconsole.log(res.fileID);});
//需先使用 wx.cloud.init 初始化,小程序端无需再引入 SDK ,且免鉴权wx.cloud.uploadFile({cloudPath: "example.png", // 上传至云端的路径filePath: "" // 小程序临时文件路径,需结合小程序相关 API 获取}).then((res) => {// 返回文件 IDconsole.log(res.fileID);});
const tcb = require("@cloudbase/node-sdk");const fs = require("fs");const app = tcb.init();app.uploadFile({cloudPath: "path/test.jpg",fileContent: fs.createReadStream("test.jpg")}).then((res) => {// 返回文件 IDconsole.log(res.fileID);});
/ 开头。文档反馈