Question

I create files in file system with webworker and synchronous method.

Is all OK but when chrome update to 33 version only can write one file. The second file show this error:

ERROR: InvalidStateError: Failed to execute 'write' on 'FileWriterSync': An operation that depends on state cached in an interface object was made but the state had changed since it was read from disk.

In android chrome (with version 32) is all OK and with desktop chrome with version 32 is all OK too.

Is a Bug?

this code is in a bucle (sync file system!!)

fs.root.getDirectory('/'+dir+'/'+dir_image, {create: true});

fileEntry=fs.root.getFile('/'+dir+'/'+dir_image+'/f_'+filename, {create: true});

blob = new Blob([xhr2BLOB.response], {type: 'image/'+arr_image[2]});

writer=fileEntry.createWriter();

writer.write(blob); //here ERROR second time!!! only version 33!!!

No correct solution

OTHER TIPS

Solution:

change responseType of xhr2(XMLhttprequest) from 'blob' to 'arraybuffer' and create blob like this:

var xhr2BLOB = new XMLHttpRequest();
xhr2BLOB.responseType='arraybuffer';

xhr2BLOB.open('GET',path_to_image, false); //SYNCHRONOUS
xhr2BLOB.send();   

var arrayBuffer = xhr2BLOB.response; 

fs.root.getDirectory('/'+dir, {create:true});

fs.root.getDirectory('/'+dir+'/'+dir_image, {create: true});
fileEntry=fs.root.getFile('/'+dir+'/'+dir_image+'/f_'+filename, {create: true});


var blob = new Blob([new Uint8Array(arrayBuffer)],{type:'image/'+arr_image[2]});

fileEntry.createWriter().write(blob);

Remember, this a webworker code with synchronous XMLhttprequest and synchronous file system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top