Multiple email attachments

I have an app that needs to send 2 PDF files via MailComposer, but I’m not certain I’m using it right as I only get 1 of the PDF files on the email. The files are stored in my assets folder.

I’m using Asset.fromModule(require('<filepath>')).downloadAsync(); to download the files on component mount, and then Asset.fromModule(require('<filepath>')).localUri to get the local file uri on button click. I do this for both PDF files and add them for use as described in https://docs.expo.io/versions/v27.0.0/sdk/mail-composer.

This works for one file (the first one I have in the array), but not the second.

I’ve tested this on android with both GMail & Inbox.

Is this a bug or am I missing something?

Hmm, that sounds reasonable. Can you reproduce it on snack.expo.io so we can investigate?

Yeah no problem, Here. For some reason it loads the files as js files (I assume because it’s in the bounds of Expo. My project has been detached so it can load pdf files with no issues). You can still see the issue though if you look at the hashes of the two files in the email app, they are both the same.

Maybe try wrapping the function with a try/catch and see if any errors surface, specifically these ones.

I think this is a snack thing :confused:


CC: @aalices :point_left:Module maker

I didn’t see anything when I added a try catch, but I took a look at Logcat and I get this error when I click the button:

Attempt to cast generated internal exception:
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
        at android.os.BaseBundle.getCharSequenceArrayList(BaseBundle.java:1233)
        at android.os.Bundle.getCharSequenceArrayList(Bundle.java:1024)
        at android.content.Intent.getCharSequenceArrayListExtra(Intent.java:7159)
        at android.content.Intent.migrateExtraStreamToClipData(Intent.java:9904)
        at android.content.Intent.migrateExtraStreamToClipData(Intent.java:9867)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1794)
        at android.app.ContextImpl.startActivity(ContextImpl.java:879)
        at android.app.ContextImpl.startActivity(ContextImpl.java:856)
        at android.content.ContextWrapper.startActivity(ContextWrapper.java:367)
        at android.content.ContextWrapper.startActivity(ContextWrapper.java:367)
        at versioned.host.exp.exponent.modules.api.MailComposerModule.composeAsync(MailComposerModule.java:107)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
        at android.os.Looper.loop(Looper.java:164)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
        at java.lang.Thread.run(Thread.java:764)

My Java is a bit rusty, but it looks like the array isn’t being parsed properly at some point in the module.

I’ve started an issue on the Expo repo here

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.