I try to upload a huge qbw file in chunks using this function.
But the file type is empty and when
I try to open it with a dedicated program , it tells me that the file has an unexpected format.
Also after merging the chunks, they are merged into one huge file,
but the file has 0 kb size.
I tried many contentType,
headers and reader methods to read chunks but the same result.
Can anyone knows what is wrong ?
// slice files in chunk chunky
chunky : function(file, loadedSize)
{ let chunkSize = 1048576 ; //1024*1024; size of one chunk var totalFileSize = file.size; // total size of file
var noOfChunks = Math.ceil(totalFileSize/chunkSize);
let reader = new FileReader();
let blob = file.slice(loadedSize, chunkSize); //a single chunk in starting of step size let requestNumber = 1;
reader.readAsBinaryString(blob); // reader.readAsDataURL( blob ); console.log('totalSize'+totalFileSize);
console.log('noOfChunksTosend' + requestNumber);
reader.onloadend = function (event)
{
if (event.target.readyState === FileReader.DONE) { //read request completed // no more chunks to send
if(event.target.result)
{ console.log('loadedSize' + loadedSize); console.log('rezult::' + event.target.result);
var dataToBeSent = {
bloby: event.target.result,
fileName: file.name,
fileType: file.type, // empty ?? fileSize: totalFileSize,
loadedSize: loadedSize,
requestNumber: requestNumber
}
jQuery.ajax({
url: IntegrationServer.path + '/uploadfileInChuncks',
type: "POST",
method: 'POST',
data: dataToBeSent,
// contenttype: "multipart/form-data",
processData: false,
contentType: false,
// this dataType: 'json',
cache:false, }).done(function (response)
{ console.log('received response: ' + response);