0

I'm working with Worklight 6.2 and I'm trying to upload an image from the camera on an Android Device with android 4.0.3, but whenever I run this code it won't complete the upload.

Here's the code:

function sendReportImage(reportID){
    WL.Logger.debug("Submitting report image: " + imageURI);

var options = new FileUploadOptions();

options.fileKey="file"; 
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode=false;

WL.Logger.debug("options" + options);

var ft = new FileTransfer();
ft.upload(imageURI, encodeURI(host + "/reports/"+reportID+"/contents"), imageUploadSuccess, imageUploadFail, options);

But it doesn't even get to the FileTransfer line, it stops on the FileUploadOptions, showing this log:

07-21 19:34:43.835: D/CordovaLog(6185):          file:///data/data/com.my_program/files/www/default/worklight/cordova.js: Line 1036 : processMessage failed: Message: S01 StoragePlugin137844502 n1
07-21 19:34:43.835: I/Web Console(6185): processMessage failed: Message: S01 StoragePlugin137844502 n1 at file:///data/data/com.my_program/files/www/default/worklight/cordova.js:1036
07-21 19:34:43.867: D/CordovaLog(6185): file:///data/data/com.my_program/files/www/default/worklight/cordova.js: Line 1037 : processMessage failed: Error: ReferenceError: FileUploadOptions is not defined
07-21 19:34:43.867: I/Web Console(6185): processMessage failed: Error: ReferenceError: FileUploadOptions is not defined at file:///data/data/com.my_program/files/www/default/worklight/cordova.js:1037
07-21 19:34:43.898: D/dalvikvm(6185): GC_CONCURRENT freed 147K, 48% free 7679K/14535K, paused 2ms+3ms
07-21 19:34:43.898: D/CordovaLog(6185): file:///data/data/com.my_program/files/www/default/worklight/cordova.js: Line 1038 : processMessage failed: Stack: ReferenceError: FileUploadOptions is not defined
07-21 19:34:43.898: D/CordovaLog(6185):     at sendReportImage (file:///data/data/com.my_program/files/www/default/js/report.js:206:2)
07-21 19:34:43.898: D/CordovaLog(6185):     at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/js/report.js:181:5)
07-21 19:34:43.898: D/CordovaLog(6185):     at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1202:33)
07-21 19:34:43.898: D/CordovaLog(6185):     at file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1047:30
07-21 19:34:43.898: D/CordovaLog(6185):     at Object.resolveWith (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1158:7)
07-21 19:34:43.898: D/CordovaLog(6185):     at Object.resolve (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1247:33)
07-21 19:34:43.898: D/CordovaLog(6185):     at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/jsonstore.js:4007:28)
07-21 19:34:43.898: D/CordovaLog(6185):     at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1202:33)
07-21 19:34:43.898: D/CordovaLog(6185):     at file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1047:30
07-21 19:34:43.898: D/CordovaLog(6185):     at Object.resolveWith (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1158:7)
07-21 19:34:43.898: I/Web Console(6185): processMessage failed: Stack: ReferenceError: FileUploadOptions is not defined
07-21 19:34:43.898: I/Web Console(6185):     at sendReportImage (file:///data/data/com.my_program/files/www/default/js/report.js:206:2)
07-21 19:34:43.898: I/Web Console(6185):     at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/js/report.js:181:5)
07-21 19:34:43.898: I/Web Console(6185):     at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1202:33)
07-21 19:34:43.898: I/Web Console(6185):     at file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1047:30
07-21 19:34:43.898: I/Web Console(6185):     at Object.resolveWith (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1158:7)
07-21 19:34:43.898: I/Web Console(6185):     at Object.resolve (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1247:33)
07-21 19:34:43.898: I/Web Console(6185):     at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/jsonstore.js:4007:28)
07-21 19:34:43.898: I/Web Console(6185):     at Object.<anonymous> (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1202:33)
07-21 19:34:43.898: I/Web Console(6185):     at file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1047:30
07-21 19:34:43.898: I/Web Console(6185):     at Object.resolveWith (file:///data/data/com.my_program/files/www/default/worklight/wljq.js:1158:7) at file:///data/data/com.my_program/files/www/default/worklight/cordova.js:1038

Any hint how to fix it?

  • Do you have the following file under the assets folder? AndroidProject/assets/www/default/worklight/plugins/org.apache.cordova.file/www/FileUploadOptions.js Also, was this a new app created in 6.2, or was it upgraded from a previous Worklight version? – Daniel A. González Jul 22 '14 at 15:25
  • No, there's no such file. It was upgraded. – user3791326 Jul 23 '14 at 17:40

2 Answers2

0

Please try the following: in your generated Android project, under assets\www\default\worklight\cordova_plugins.js, find and replace:

- "file": "plugins/org.apache.cordova.file/www/FileUploadOptions.js",
+ "file": "plugins/org.apache.cordova.file/www/fileuploadoptions.js",

Additionaly,
See this question and answer: IBM Worklight 6.2 - error on StoragePlugin

There is a known defect with the declaration of the Storage plug-in, which may be the root cause here. As a workaround, you need to open config.xml and alter it as follows:

- com.worklight.androidgap.plugin.storage.StoragePlugin
+ com.worklight.androidgap.plugin.StoragePlugin

Please let us know if, and which, of the above (maybe both are required) helped you.
If you are an IBM customer or business partner, you'll need to open a PMR to receive an iFix containing the fix for this issue.

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • The StoragePlugin part is done, but under the assets\www I only find a file called "resources.zip.unencrypted.001". There's no "default" folder. – user3791326 Jul 23 '14 at 16:53
  • Sounds like you've used the encrypt web resources option in application-descriptor.xml; you will not be able to access the default folder because you've encrypted it. – Idan Adar Jul 23 '14 at 17:00
  • In the application-descriptor.xml this option is like this: This folder is only on my iphone environment. – user3791326 Jul 23 '14 at 17:07
  • I don't see this here; try again with a new project and application. – Idan Adar Jul 23 '14 at 17:07
  • Well, I did the Android environment again and now the folders are there. I replaced what you said, but still not working here.It keeps saying the FileUploadOptions is not defined on the cordova.js. – user3791326 Jul 23 '14 at 18:07
0

Now it's working, here's what I had to do:

Find the file "assets/www/default/plugins/org.apache.cordova.file/www/FileUploadOptions.js" on the generated Android project and open it. On the top of the "FileUploadOptions.js" file'code there's something like this:

cordova.define("org.apache.cordova.file.FileUploadOptions1", function(require, exports, module) {

Change to this code as follows:

cordova.define("org.apache.cordova.file.FileUploadOptions", function(require, exports, module) {

Saved the file and choosed "Run as > Android application". No errors now.

  • This is only a workaround, as the next time you will build your project in Worklight Studio - the file you've edited will be restored to how it is originally, with the error. If you are an IBM customer, you'll need to open a PMR in order to receive a fixed version. I have opened a defect for this issue, thanks for the deeper investigation. – Idan Adar Jul 23 '14 at 19:24