(f:FileWithHandle, account, container)
| 148 | const dataSourceClient = DataSourceClientFactory(ClientType.API, filesQuery.data, dataSourcesQuery.data, instance); |
| 149 | |
| 150 | async function uploadBlob(f:FileWithHandle, account, container) { |
| 151 | // Create azure blob client |
| 152 | const blobName = f.name; |
| 153 | const sas_token = await fetchSasToken(dataSourceClient, account, container, blobName, true); // Note - it needs ADD, CREATE, WRITE |
| 154 | const blobUrl = `https://${account}.blob.core.windows.net/${container}/${blobName}?${sas_token.data.sasToken}`; |
| 155 | |
| 156 | const blockBlobClient = new BlockBlobClient(blobUrl); |
| 157 | |
| 158 | // chunking related |
| 159 | const blockSize = 1 * 1024 * 1024; // 1MB |
| 160 | const blockCount = Math.ceil(f.size / blockSize); |
| 161 | console.log(blockCount, 'blocks'); |
| 162 | const blockIds = []; |
| 163 | for (let i = 0; i < blockCount; i++) { |
| 164 | setProgress((i / blockCount) * 100); // update progress bar |
| 165 | const start = i * blockSize; |
| 166 | const end = Math.min(start + blockSize, f.size); |
| 167 | const chunk = f.slice(start, end); |
| 168 | const chunkSize = end - start; |
| 169 | const blockId = btoa('block-' + i.toString().padStart(6, '0')); |
| 170 | blockIds.push(blockId); |
| 171 | await blockBlobClient.stageBlock(blockId, chunk, chunkSize); |
| 172 | } |
| 173 | await blockBlobClient.commitBlockList(blockIds); |
| 174 | setProgress(100); |
| 175 | |
| 176 | } |
| 177 | |
| 178 | const uploadFiles = async () => { |
| 179 | const files = await fileOpen({ |
no test coverage detected