2

I'm trying to upload an image to Firebase.

...
if(image != null){
            storageRef.child("images").child(getUniqueName()).putBytes(compressImage(image, c.getContentResolver()))
...

and compressImage method:

public static byte[] compressImage(Uri data, ContentResolver resolver) {
   Bitmap bmpSample;
    try {
        bmpSample = MediaStore.Images.Media.getBitmap(resolver, data);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        bmpSample.compress(Bitmap.CompressFormat.JPEG, 0, out);
        byte[] byteArray = out.toByteArray();
        Log.d("image size", byteArray.length/1024+"");
        return byteArray;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

"image size" in the log is 81KB which is smaller than 1MB. Can anyone suggest why do I get these exceptions?

android.os.TransactionTooLargeException: data parcel size 20173896 bytes
                                                                             at android.os.BinderProxy.transactNative(Native Method)
                                                                             at android.os.BinderProxy.transact(Binder.java:503)
                                                                             at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:5453)
                                                                             at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:96)
                                                                             at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                                             at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

and:

D/Error: ERR: stack=java.lang.StackOverflowError: stack size 8MB
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source)
                                                                    at com.google.android.gms.internal.zzbqi.zzax(Unknown Source)

EDIT: The weird thing is that the files do show in the Firebase Storage in the console.

Community
  • 1
  • 1
ben
  • 1,064
  • 3
  • 15
  • 29
  • without image does it work ? – Orest Savchak Dec 26 '16 at 15:52
  • yes, I've been using the `FirebaseDatabase` and it works fine – ben Dec 26 '16 at 16:02
  • no, i mean now, if you comment it out, storageRef.child("images").child(getUniqueName()).putBytes(compressImage(image, c.getContentResolver())), does it work ok? – Orest Savchak Dec 26 '16 at 16:06
  • I ran your code on an older KitKat device. It successfully uploaded an image that compressed to 150KB. Add more `Log` statements and post more of your logcat output so we can see the context in which the exceptions occur. – Bob Snyder Dec 26 '16 at 18:09

0 Answers0