Question

In Chrome 32, I've got an JS app where I write raw images from a canvas to a file and I want to close the file and open it for processing in a worker. I pass the file name to the worker and I can see that it's found and opened but as soon as I try to read it I get a DOM exception (NotFoundError).

// In my worker:
fs = self.requestFileSystemSync(self.PERSISTENT, quota);
var f = fs.root.getFile(rawFileName, {create: false});  // this works, f is valid
var reader = new FileReaderSync();
// At this point, 'reader' looks ok
rawFramesArrayBuffer = reader.readAsArrayBuffer(f); // My exception is thrown here.
log("Opened " + rawFileName + " for reading.");

In my main thread, I've tried setting my File and FileWriter to undefined to ensure the file is closed (I can't see a method for doing this), but it doesn't help. In any event, the spec says that a NotReadableError should be thrown if the file is locked, but I don't see this.

If I step through the code, everything pauses for about 5 seconds when I step over the readAsArrayBuffer line and then the NotFoundError is thrown.

If I create a DirectoryReader and enumerate all the files, I can see that my file exists.

Was it helpful?

Solution 2

I needed to access the file via the FileEntry:

rawFramesArrayBuffer = reader.readAsArrayBuffer(f.file());

OTHER TIPS

You may want to pass the images to the worker rather than saving them and having the worker open a file.

Here is a page with sample code

http://kinderas.blogspot.com/2011/06/html-5-web-workers-and-image-processing.html

But it does depend on how big your image is.

I found this interesting but haven't tried to do processing from the computer camera so it may help you out.

http://blog.aviary.com/posts/live-image-processing-with-getusermedia-and-web-workers

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