1

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.

edoloughlin
  • 5,821
  • 4
  • 32
  • 61

2 Answers2

1

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

James Black
  • 41,583
  • 10
  • 86
  • 166
  • Thanks, but I'm saving images at 25fps for a few minutes. It could end up being a few gigs of data. I'd rather have it persisted to disk and then process it. – edoloughlin Feb 03 '14 at 01:19
  • The second link is doing video from the camera, which I found impressive. The web worker can save them then process when finished. – James Black Feb 03 '14 at 02:10
  • Thanks. I'll give it a look tomorrow (it's late here). You're welcome to an upvote, but I'd still like to know why I'm getting that exception. – edoloughlin Feb 03 '14 at 02:25
  • Unfortunately it seems to be a delay in closing, but I also don't see a close() function in the api. So having the web worker do the saving seems the simplest solution. – James Black Feb 03 '14 at 03:25
  • It's quite a delay. I 'close' the file (set my reference to the File and FileWriter to null) and then wait for the user to click a button before continuing. – edoloughlin Feb 03 '14 at 09:19
  • Turns out I get the same error if I put all my file handling in the worker. I can't open a reader on a file I've been writing. – edoloughlin Feb 03 '14 at 23:33
  • Look at the accepted answer here,http://stackoverflow.com/questions/19744155/writing-file-to-desktop-using-html5-filesystem-api – James Black Feb 04 '14 at 02:34
  • Thanks, but I'm not sure there's any overlap. What I'm trying to do is confined to the browser's environment. I.e., write a large amount of data to a file and then read it back for processing. All within the sandbox - the user isn't even aware that a file is being written (apart from needing to grant permission). – edoloughlin Feb 04 '14 at 17:22
0

I needed to access the file via the FileEntry:

rawFramesArrayBuffer = reader.readAsArrayBuffer(f.file());
edoloughlin
  • 5,821
  • 4
  • 32
  • 61