MCPcopy Create free account
hub / github.com/apitable/apitable / upload

Function upload

packages/widget-sdk/src/utils/upload.ts:70–115  ·  view source on GitHub ↗
(params: {
  file: File,
  datasheetId: string;
  /** */
  onProgress?: (response: IUploadProgress) => void;
})

Source from the content-addressed store, hash-verified

68 * ```
69 */
70export function upload(params: {
71 file: File,
72 datasheetId: string;
73 /** */
74 onProgress?: (response: IUploadProgress) => void;
75}): Promise<IAttachmentValue> {
76 const { file, datasheetId, onProgress } = params;
77 return new Promise(async(resolve, reject) => {
78 if (!file || !datasheetId) {
79 reject({ message: 'file or datasheetId is required' });
80 }
81
82 const res = await uploadAttachToS3({
83 file,
84 fileType: UploadType.DstAttachment,
85 nodeId: datasheetId,
86 axiosConfig: {
87 onUploadProgress: ({ loaded, total }) => {
88 return onProgress && onProgress({ loaded, total });
89 },
90 },
91 });
92
93 const { success, data, message } = res.data;
94 if (!success) {
95 reject({
96 message
97 });
98 return;
99 }
100
101 resolve(pickBy({
102 id: data.token,
103 name: data.name || file.name,
104 mimeType: data.mimeType,
105 token: data.token,
106 bucket: data.bucket,
107 size: data.size,
108 width: data.width,
109 height: data.height,
110 preview: data.preview,
111 previewUrl: data.preview ? cellValueToImageSrc(data, { isPreview: true }) : undefined,
112 url: cellValueToImageSrc(data),
113 }, identity) as IAttachmentValue);
114 });
115}

Callers

nothing calls this directly

Calls 2

uploadAttachToS3Function · 0.90
cellValueToImageSrcFunction · 0.90

Tested by

no test coverage detected