0

WL 6.0.0.1

I'm working with files, sending and receiving them between the backend and the worklight app.

I'm using adapters and custom phonegap plugins developed by me to send and receive files.

The issue I'm having is that with iPad I can not work with files > 5mg and in Android with API 2.2 (so not using android:largeHeap="true") I can not work with files > 3mg. In case of using largeHeap = true I can not work with files > 5mg

With bigger file sizes I get out of memory.

What I'm doing is from the app request a file from the backend using an adapter, the adapter using java reads the file in byte[] and code it to a base64 String that is returned, then the app pass this base64 string to a phonegap plugin and the plugin decode it to a byte[] and write it to the disk.

The adapter side is working after setting a heap size of 1024mg, the app size throws out of memory exceptions.

For sending files I have the issue with my plugin, coding the byte[] to base64 String, I understand it needs to make a copy of the data so it multiply *2 the needed memory, any was it sounds strange. I will try to debug the Base64 code...

For receiving I get the Out Of Memory after calling the adapter and before the adapter callbacks.

So:

WL.Logger.debug('Invoking Load File Adapter');
WL.Client.invokeProcedure(invocationData, invocationOptions );

function successLoadFile(ret)
{
    WL.Logger.debug('Into Load File adapter success');

I see the trace "Invoking Load File Adapter" but I do not see the trace "Into Load File adapter success" nor "Error" one.

The log is:

E/dalvikvm-heap(11623): Out of memory on a 17994284-byte allocation.
I/dalvikvm(11623): "WebViewCoreThread" prio=5 tid=11 RUNNABLE
I/dalvikvm(11623):   | group="main" sCount=0 dsCount=0 obj=0x41a7ed28 self=0x583d2558
I/dalvikvm(11623):   | sysTid=11636 nice=0 sched=0/0 cgrp=[no-cpu-subsys] handle=1368554752
I/dalvikvm(11623):   | schedstat=( 173239349436 4901367062 38904 ) utm=16976 stm=347 core=1
I/dalvikvm(11623):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~94)
I/dalvikvm(11623):   at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:162)
I/dalvikvm(11623):   at java.lang.StringBuilder.append(StringBuilder.java:311)
I/dalvikvm(11623):   at org.json.JSONTokener.nextString(JSONTokener.java:224)
I/dalvikvm(11623):   at org.json.JSONTokener.nextValue(JSONTokener.java:107)
I/dalvikvm(11623):   at org.json.JSONTokener.readArray(JSONTokener.java:430)
I/dalvikvm(11623):   at org.json.JSONTokener.nextValue(JSONTokener.java:103)
I/dalvikvm(11623):   at org.json.JSONArray.<init>(JSONArray.java:87)
I/dalvikvm(11623):   at org.json.JSONArray.<init>(JSONArray.java:103)
I/dalvikvm(11623):   at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:65)
I/dalvikvm(11623):   at org.apache.cordova.api.PluginManager.exec(PluginManager.java:224)
I/dalvikvm(11623):   at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:44)
I/dalvikvm(11623):   at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
I/dalvikvm(11623):   at android.webkit.JWebCoreJavaBridge.nativeServiceFuncPtrQueue(Native Method)
I/dalvikvm(11623):   at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:113)
I/dalvikvm(11623):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm(11623):   at android.os.Looper.loop(Looper.java:137)
I/dalvikvm(11623):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:1067)
I/dalvikvm(11623):   at java.lang.Thread.run(Thread.java:856)
E/Mapfre(11623): [http://192.168.1.39:10080/Mapfre/apps/services/api/Mapfre/android/query] exception. Error: Error calling method on NPObject.

I have tried with .txt .ppt and .pdf.

Thank you.

Jxadro
  • 1,497
  • 2
  • 16
  • 36
  • What version of Worklight are you using ? Also, at what stage does the OutOfMemory occur - does it happen during `invokeProcedure` or when you call the Plugin to decode ? – Srik Dec 02 '13 at 06:13

2 Answers2

0

As Idan says, adapter calls are not for fetching large amounts of data. However, one workaround you can use is the compressResponse option while calling invokeProcedure. See this link for documentation,

Srik
  • 7,907
  • 2
  • 20
  • 29
0

Worklight adapters are not meant for sending large data files. You should not use Worklight adapters for this purpose.

You can instead use Cordova plug-ins or otherwise native implementation to handle sending large files.

As for the crashing, I would think this is related to the device, whether it is an older or newer one... to overcome this perhaps you can implement multi-part sending; this will require work on by the server- and client-side.

Possible related questions:

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Ok, working with files makes the solution complex, the big pictures is that I manage Customer entities with simple information and files, these entities must be sync with the backend when they are modified using the app. So when files comes into the picture, you can not use JSON in an easy way because you can not have large information in the JSON Store (http://stackoverflow.com/questions/20307975/jsonstore-error-when-push-a-collection-with-documents-with-files) and you can not use adapters to synch those files. I will try to explain all this in the demo... Thank you all. – Jxadro Dec 02 '13 at 12:18
  • I think that for files the best solution is to use the phonegap File API instead of adapters for handling files. FileTransfer class http://docs.phonegap.com/en/3.2.0/cordova_file_file.md.html#FileTransfer . And if needed build an intermediate piece in the server for merging information. – Jxadro Dec 02 '13 at 16:52
  • Just make sure to follow the correct Cordova API; for Worklight 6.0.0.x it is v2.6. – Idan Adar Dec 02 '13 at 16:53