Sending a phone's saved asset via expo-mail-composer

Viewed 9

I am working on a page that will record a video, and once that video has finished recording, the user can hit a button that will compose an email to another user, with that aforementioned video as an attachment. The expo documentation doesn't go into much detail as to how this uri should be formatted, only that it needs to be a uri that is also saved on the phone. This being said, I successfully add the video to my phone (I've tested this) using the following code...

 // Adds taken picture to Media Library
  async function saveVidToLib(vidPath){
    return await MediaLibrary.createAssetAsync(videoPath)
  }

console.log-ing this will return

{
  "creationTime": 1663870461000,
  "duration": 0.23333333333333334,
  "filename": "IMG_0331.MOV", 
  "height": 1920,
  "id": "198EADE8-FCAF-4D10-AB4E-0ECCB716EF38/L0/001", 
  "mediaSubtypes": [], 
  "mediaType": "video", 
  "modificationTime": 1663870462385, 
  "uri": "ph://198EADE8-FCAF-4D10-AB4E-0ECCB716EF38", 
  "width": 1080
}

but composing the email using that "uri" prop as the attachment errors out. Consider the code below, understanding that video is equal to the object shown above

  // Emails the now saved video
  async function emailVid(video){
    MailComposer.composeAsync({
      recipients: [therapist.email],
      subject: `Video Of Exercise From: ${user.firstName} ${user.lastName}`,
      body: "Beta Testing",
      attachments: [video.uri]
    }).catch((err) => console.log(err))
  }

The above code then gives me a huge terrible error, but with this to lead it off

{"code": "ERR_ARGUMENT_CAST", "domain": "RCTErrorDomain", "message": "Argument at index '0' couldn't be cast to type MailComposerOptions
→ Caused by: Cannot cast '(
        {
        creationTime = 1663870461000;
        duration = \"0.2333333333333333\";
        filename = \"IMG_0329.MOV\";
        height = 1920;
        id = \"AD8280CF-3FE9-4D0C-97C9-D1ACBF501B18/L0/001\";
        mediaSubtypes =         (
        );
        mediaType = video;
        modificationTime = 1663870462385;
        uri = \"ph://AD8280CF-3FE9-4D0C-97C9-D1ACBF501B18\";
        width = 1080;
    }
)' for field 'attachments' of type Optional<Array<URL>>
→ Caused by: Cannot convert 'Optional({
    creationTime = 1663870461000;
    duration = \"0.2333333333333333\";
    filename = \"IMG_0329.MOV\";
    height = 1920;
    id = \"AD8280CF-3FE9-4D0C-97C9-D1ACBF501B18/L0/001\";
    mediaSubtypes =     (
    );
    mediaType = video;
    modificationTime = 1663870462385;
    uri = \"ph://AD8280CF-3FE9-4D0C-97C9-D1ACBF501B18\";
    width = 1080;
})' to URL", 
0 Answers
Related