@ccw-api/api
    Preparing search index...
    • 获取 COS 直传策略(post-policy)

      Parameters

      • purpose: StoragePurpose

        存储用途

      • fileName: string

        文件名

      • contentType: string

        文件 MIME 类型

      • fileSize: number

        文件大小(字节)

      • contentHash: string

        文件内容哈希

      • OptionalprojectOid: string

        项目 OID(PROJECT_ASSET / PROJECT_SB3 必传,其余可选)

      Returns Promise<CosPostPolicyRes>

      COS 直传策略,含预签名 policy、resourceUrl 等

      {
      "bucket": "zhishi-1317963717",
      "expireAt": "2026-10-17T04:04:26.890274Z",
      "fields": {
      "q-sign-algorithm": "sha1",
      "x-cos-forbid-overwrite": "true",
      "q-ak": "AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "q-signature": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "q-key-time": "0000000000;0000000000",
      "q-sign-time": "0000000000;0000000000",
      "key": "user_projects_assets/example.svg",
      "Content-Type": "image/svg+xml",
      "policy": "eyJleHBpcmF0aW9uIjoiLi4uIn0="
      },
      "forbidOverwrite": true,
      "objectKey": "user_projects_assets/example.svg",
      "objectPrefix": "user_projects_assets/",
      "provider": "COS",
      "resourceUrl": "https://m.ccw.site/user_projects_assets/example.svg",
      "reviewRequired": true,
      "reviewType": "IMAGE",
      "url": "https://zhishi-1317963717.cos.ap-beijing.myqcloud.com"
      }

      拿到策略后,使用 FormData 直接向 res.url POST 上传(fields 顺序无关,file 必须最后):

      const policy = await getStoragePostPolicy(...);
      const form = new FormData();
      Object.entries(policy.fields).forEach(([k, v]) => form.append(k, v));
      form.append("file", file, fileName);
      await fetch(policy.url, { method: "POST", body: form });
      // 上传成功后文件地址:policy.resourceUrl