tencent cloud

CloudBase

Product Introduction
Product Overview
Features and Strengths
Use Cases
System Limits
Purchase Guide
Product Pricing
Description Of Billing Capability Items
Yearly/Monthly Subscription Package Description
Alarm and Notification
Overdue Payment Instructions
Development Guide
Cloud Storage
Database
Identity Verification
Cloud function
Static website management
SDK Documentation
Client SDK
Server SDKs
Management-side SDK
Product Agreement
Cloud Development Service Level Agreement

Uploading Files

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2025-12-31 11:48:16
You can upload any number and format of files to the cloud storage of CloudBase (TCB), and customize the paths and names of files and directories.
Note:
By default, only users who have passed CloudBase identity authentication can upload files to the cloud storage space. Therefore, login authentication should be performed first when files are uploaded on the user side (such as Web).
You can also use cloud storage security rules to set looser or stricter read/write permissions for cloud storage.
You can use the SDK to upload files to cloud storage space and return the globally unique identifier fileID of the file.
Web
WeChat Mini Program
Node.js
//Step 1: Introduce the Web SDK.
import tcb from "@cloudbase/js-sdk";

//Step 1: Perform initialization.
const app = tcb.init({
env: "your-env-id"
});

/**
Step 3: Login authentication process. The code is omitted here. See:
https://www.tencentcloud.com/document/product/876/41728?from_cn_redirect=1
*/

app
.uploadFile({
// Path of cloud storage.
cloudPath: "dirname/filename",
// File to be uploaded. File type.
filePath: document.getElementById("file").files[0]
})
.then((res) => {
// Return the file ID.
console.log(res.fileID);
});

//First, use wx.cloud.init for initialization. There is no need to import the SDK again on the mini program side, and authentication is not required.
wx.cloud
.uploadFile({
cloudPath: "example.png", // Path of uploading files to the cloud.
filePath: "" // Temporary file path for mini programs, which needs to be obtained by combining with APIs related to mini programs.
})
.then((res) => {
// Return the file ID.
console.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) => {
// Return the file ID.
console.log(res.fileID);
});

Note:
During upload, the file name should comply with filename specification.
cloudPath is the relative root directory path to a file or folder in cloud storage, in the form of directory/filename. It does not need to start with /.
If a file is uploaded to the same path, it will overwrite the existing file. By default, User A is not allowed to overwrite User B's files.


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백