(params: {
file: File,
datasheetId: string;
/** */
onProgress?: (response: IUploadProgress) => void;
})
| 68 | * ``` |
| 69 | */ |
| 70 | export 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 | } |
nothing calls this directly
no test coverage detected