0
votes

I write a phonegap app and in it I will copy a file selected in android gallery to SD-Card. This function works, but freeze the Main Thread for the copy time.

Now I tested to write this in a Web Worker, I post the fileEntry to Web Worker but there comes an Error:

03-18 09:31:37.575    1713-1713/de.scisys.app I/chromium﹕ [INFO:CONSOLE(1)] "Uncaught TypeError: Object #<Object> has no method 'copyTo'", source: blob:file%3A///7fd968c1-2d2b-469e-b4b7-fab1172bb496 (1)

Here is my Code:

function(fileEntry) {
    ...
    var blob = new Blob(['onmessage = function(e) { var data = e.data; data.fileEntry.copyTo(data.parentEntry, data.newName, function() { postMessage("success") }, function() { postMessage("error") }); }'], {type: 'text/javascript'});
    var blobURL = window.URL.createObjectURL(blob);

    var worker = new Worker(blobURL);
    worker.onmessage = function(e) {
        alert(e.data)
    };
    worker.postMessage({'fileEntry': fileEntry, 'parentEntry': parentEntry, 'newName': fileId+"."+fileName[fileName.length-1]});
    ...
}

Is there an error in my code, or have some one an idea?

Thanks for your help!

Edit: I found a Solution by editing the Phonegap Core File Plugin. In FileUtils "execute" method I changed the work to Thread. http://www.mindfiresolutions.com/Implementing-MultiThreading-In-Android-Plugin-For-PhoneGap-260-2572.php

1

1 Answers

-1
votes

As per my knowledge Web Workers never works on local directory

file://

it works on server side. For example instead of placing files at "file://" so the path should be

***> http://locahost/ or***
***> http://server_ip_address***

Hence Phonegap consists of HTML and Javascript which are at device directory hence web workers are not supported in Phonegap. ^^is what I found out just a small googling :) . Please google first