Item Chunk Count and chunk index in CHUNK_EVENTS.CHUNK_START not coming Properly #189
-
Hi, I have kept a CHUNK_EVENTS.CHUNK_START event listener to add total number of chunks and chunk index to the header. But issue which i am seeing is that chunk index is always coming as zero and total chunks are actually total chunks remaining to upload. Not sure if this is intended. To overcome this i have done following implementation - uploader.on(CHUNK_EVENTS.CHUNK_START, (item) => {
if(totalChunks === 0){
totalChunks = item.chunkCount;
}
return {
sendOptions: {
headers: {
"Total-Chunks": totalChunks,
"Chunk-Number": totalChunks-item.chunkCount + 1
}
}
};
}); Is it possible to get directly the chunk index number and total chunk counts. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
For the chunk index, This should get you the correct info: uploader.on(CHUNK_EVENTS.CHUNK_START, ({ chunk }) => {
const { index } = chunk;
const chunkNumber = index + 1; //index is 0 based
//...
}); As for the total count. You are right, the chunkCount is updated down as chunks are being sent. I will need to think about this to at least rename (ex: remainingCount), to make sure its much clearer. I will also add a new prop that will hold the total count without updating it so it can be used as you need it. For now, Im afraid there is no pretty solution until I make the changes. The best thing is probably storing the total when the first chunk is encountered: const chunkTotals = {};
uploader.on(CHUNK_EVENTS.CHUNK_START, ({ chunk, item, chunkCount }) => {
const { index } = chunk;
//store the real total on the first chunk
if (index === 0) {
chunkTotals[item.id] = chunkCount
}
const totalChunks = chunkTotals[item.id]
//clean up on the last chunk
if (chunkCount === 0) {
delete chunkTotals[item.id];
}
//...
});
not pretty, I know. I will open an issue for the issues above |
Beta Was this translation helpful? Give feedback.
Hi @vinodkhandelwal
For the chunk index, This should get you the correct info:
As for the total count. You are right, the chunkCount is updated down as chunks are being sent. I will need to think about this to at least rename (ex: remainingCount), to make sure its much clearer.
I will also add a new prop that will hold the total count without updating it so it can be used as you need it.
For now, Im afraid there is no pretty solution until I make the changes. The best thing is probably storing the total when the first chunk i…