面向 cc 的编程规则,帮助你在任意页面仅通过 cid
即可加载与使用存储工具,无需关注 Provider 细节。
cid
:使用 NovaStorage.withCid(cid)
自动选择企业账套 Provider。NovaFile
,含 key
, url
, name
, type
, size
, metadata
, md5
等。storage/company/<cid>/<prefixKey?>/<YYYYMMDD>/<HHmmss-rand>-<name>
。prefixKey
在公司段后、日期目录前插入自定义目录(自动去除首尾斜杠)。getAttachmentByMd5
与 saveAttachment
,避免重复上传并统一写入 Attachment
。import { NovaStorage, NovaFile } from 'fmode-ng/core';
const cid = localStorage.getItem('company')!; // 或服务获取
const storage = await NovaStorage.withCid(cid);
const file = (event.target as HTMLInputElement).files![0];
const uploaded: NovaFile = await storage.upload(file, {
prefixKey: 'project/pid/', // 项目页需要加项目前缀
onProgress: (p) => console.log('progress %', p.total.percent),
});
console.log(uploaded.key, uploaded.url);