Agent skill

cloud-storage-web

Complete guide for CloudBase cloud storage using Web SDK (@cloudbase/js-sdk) - upload, download, temporary URLs, file management, and best practices.

Stars 42
Forks 3

Install this agent skill to your Project

npx add-skill https://github.com/TencentCloudBase/skills/tree/main/skills/cloud-storage-web

SKILL.md

Cloud Storage Web SDK

Activation Contract

Use this first when

  • A browser or Web app must upload, download, or manage CloudBase storage objects through @cloudbase/js-sdk.
  • The request mentions uploadFile, getTempFileURL, deleteFile, or downloadFile in frontend code.

Read before writing code if

  • The task is browser-side storage work but you still need to separate it from Mini Program storage, backend storage management, or static hosting deployment.
  • The request may be blocked by security domains or frontend auth.

Then also read

  • Web login and identity -> ../auth-web/SKILL.md
  • General Web app setup -> ../web-development/SKILL.md
  • Direct storage management through MCP tools -> ../cloudbase-platform/SKILL.md

Do NOT use for

  • Mini Program file APIs.
  • Backend or agent-side direct storage management through MCP.
  • Static website hosting deployment via uploadFiles.
  • Database operations.

Common mistakes / gotchas

  • Uploading from browser code without configuring security domains.
  • Using this skill for static hosting instead of storage objects.
  • Mixing browser SDK upload flows with server-side file-management tasks.
  • Assuming temporary download URLs are permanent links.

Minimal checklist

  • Confirm the caller is a browser/Web app.
  • Initialize the Web SDK once.
  • Check security-domain/CORS requirements.
  • Pick the right storage method before coding.

Overview

Use this skill for browser-side cloud storage operations through the CloudBase Web SDK.

Typical tasks:

  • upload files from a browser
  • generate temporary download URLs
  • delete files
  • trigger browser downloads

SDK initialization

javascript
import cloudbase from "@cloudbase/js-sdk";

const app = cloudbase.init({
  env: "your-env-id"
});

Initialization rules:

  • Use synchronous initialization with a shared app instance.
  • Do not re-initialize in every component.
  • If the operation depends on user identity, handle auth before storage operations.

Method routing

  • Upload from browser -> app.uploadFile()
  • Temporary preview/download URL -> app.getTempFileURL()
  • Delete existing files -> app.deleteFile()
  • Trigger browser download -> app.downloadFile()

Upload

javascript
const result = await app.uploadFile({
  cloudPath: "uploads/avatar.jpg",
  filePath: selectedFile
});

Upload rules

  • cloudPath must include the filename.
  • Use / to create folder structure.
  • Validate file type and size before upload.
  • Show upload progress for larger files when UX matters.

Progress example

javascript
await app.uploadFile({
  cloudPath: "uploads/avatar.jpg",
  filePath: selectedFile,
  onUploadProgress: ({ loaded, total }) => {
    const percent = Math.round((loaded * 100) / total);
    console.log(percent);
  }
});

Temporary URLs

javascript
const result = await app.getTempFileURL({
  fileList: [
    {
      fileID: "cloud://env-id/uploads/avatar.jpg",
      maxAge: 3600
    }
  ]
});

Use temp URLs when the browser needs to preview or download private files without exposing a permanent public link.

Delete files

javascript
await app.deleteFile({
  fileList: ["cloud://env-id/uploads/old-avatar.jpg"]
});

Always inspect per-file results before assuming deletion succeeded.

Download files

javascript
await app.downloadFile({
  fileID: "cloud://env-id/uploads/report.pdf"
});

Use this for browser-initiated downloads. For programmatic rendering or preview, prefer getTempFileURL().

Security-domain reminder

To avoid CORS problems, add your frontend domain in CloudBase console security domains.

Typical examples:

  • http://localhost:3000
  • https://your-app.com

Best practices

  1. Use a clear folder structure such as uploads/, avatars/, documents/.
  2. Validate file size and type in the browser before upload.
  3. Use temporary URLs with reasonable expiration windows.
  4. Clean up obsolete files instead of leaving orphaned storage objects.
  5. Route privileged batch-management tasks to backend or MCP flows instead of browser direct access.

Error handling

javascript
try {
  const result = await app.uploadFile({
    cloudPath: "uploads/file.jpg",
    filePath: selectedFile
  });
  console.log(result.fileID);
} catch (error) {
  console.error("Storage operation failed:", error);
}

Expand your agent's capabilities with these related and highly-rated skills.

TencentCloudBase/skills

miniprogram-development

WeChat Mini Program development skill for building, debugging, previewing, testing, publishing, and optimizing mini program projects. This skill should be used when users ask to create, develop, modify, debug, preview, test, deploy, publish, launch, review, or optimize WeChat Mini Programs, mini program pages, components, routing, project structure, project configuration, project.config.json, appid setup, device preview, real-device validation, WeChat Developer Tools workflows, miniprogram-ci preview/upload flows, or mini program release processes. It should also be used when users explicitly mention CloudBase, wx.cloud, Tencent CloudBase, 腾讯云开发, or 云开发 in a mini program project.

42 3
Explore
TencentCloudBase/skills

spec-workflow

Use when medium-to-large changes need explicit requirements, technical design, and task planning before implementation, especially for multi-module work, unclear acceptance criteria, or architecture-heavy requests.

42 3
Explore
TencentCloudBase/skills

ui-design

Use when users need visual direction, interface hierarchy, layout decisions, design specifications, or prototypes before implementing a Web or mini program UI.

42 3
Explore
TencentCloudBase/skills

cloudbase-platform

CloudBase platform overview and routing guide. This skill should be used when users need high-level capability selection, platform concepts, console navigation, or cross-platform best practices before choosing a more specific implementation skill.

42 3
Explore
TencentCloudBase/skills

ai-model-wechat

Use this skill when developing WeChat Mini Programs (小程序, 企业微信小程序, wx.cloud-based apps) that need AI capabilities. Features text generation (generateText) and streaming (streamText) with callback support (onText, onEvent, onFinish) via wx.cloud.extend.AI. Built-in models include Hunyuan (hunyuan-2.0-instruct-20251111 recommended) and DeepSeek (deepseek-v3.2 recommended). API differs from JS/Node SDK - streamText requires data wrapper, generateText returns raw response. NOT for browser/Web apps (use ai-model-web), Node.js backend (use ai-model-nodejs), or image generation (not supported).

42 3
Explore
TencentCloudBase/skills

cloudbase-document-database-web-sdk

Use CloudBase document database Web SDK to query, create, update, and delete data. Supports complex queries, pagination, aggregation, realtime, and geolocation queries.

42 3
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results