previewUrl is a relative URL. To flush out the code even more... the
previewUrl is generated like this:
previewUrl = jQuery.uuid();
store.captureBlob(files[i].blob, previewUrl);
where files[i].blob is one entry in the array of files passed to the
callback of a Desktop.openFiles() call.
The worker javascript is loaded from the same domain and directory as
the main javascript. The main javascript is included on the page like
this:
src="/javascript/gears_pup_v4.js?v=20090114"
That javascript file then gets the worker using the following:
wp.createWorkerFromUrl('/javascript/gears_pup_worker.js?v=1');
The page itself (the page which loads the main javascript) is in the
same domain (clearly), but at a different URL, not under /javascript/
(as you might imagine).
What I find most confusing is that the captureBlob() / getAsBlob()
calls work fine when called from the main thread/program, but fail
when called from the worker. As far as I can see, both the main
program and the worker should have similar access to the localstore.
As a further note, if I retrieve the blob in the main program, and
pass it as an argument in the message to worker, everything works
fine.
Thanks for any insight you can lend here.
Dave Viner
On Mar 3, 12:06 pm, Michael Nordman <[email protected]> wrote:
> Is 'previewUrl' and absolute or relative url? If relative it will be
> interpreted as relative the base url of page/worker. Are the worker
> and page located in different directories?
>
> On Tue, Mar 3, 2009 at 12:19 AM, dviner <[email protected]> wrote:
>
> > Hi all,
>
> > Can ResourceStores be shared among workers?
>
> > I have a main script which stores information into a ResourceStore for
> > temporary storage. Later, I want to use a worker to access that entry
> > in the ResourceStore in order to upload it to a remote server. When a
> > worker attempts to retrieve the data from the ResourceStore, it is
> > unable to access that information. More specifically, the code that
> > I'm using looks as follows (I've redacted a bunch of error checking to
> > make it more manageable).
>
> > (main program)
> > localServer = google.gears.factory.create('beta.localserver');
> > store = localServer.createStore('tester');
> > store.captureBlob(blob, previewUrl);
>
> > (then later in the worker process)
> > localServer = google.gears.factory.create('beta.localserver');
> > store = localServer.createStore('tester');
> > blob = store.getAsBlob(previewUrl);
>
> > The worker process' call to store.getAsBlob always throws an
> > exception.
>
> > When the identical functions are called from within one javascript
> > program (i.e., without any workerpool usage), it works as expected.
> > In addition, debugging shows that the value of 'previewUrl' has the
> > same value in the main process and the worker process. So, I'm fairly
> > confident that this issue is directly related to the Store itself.
>
> > For what it's worth, I also tried passing the store itself from the
> > main program to the worker program in a message. However, Firefox
> > threw an error saying that the Gears module could not be marshaled.
>
> > Is there a way for workers and the main program to share information
> > within a ResourceStore?
>
> > Thanks
> > Dave Viner