katzer / cordova-plugin-email-composer

Edit and send email messages
Apache License 2.0
343 stars 333 forks source link

How to attach files in iOS? #358

Closed jfoclpf closed 3 years ago

jfoclpf commented 3 years ago

As you can see here: https://cordova.apache.org/docs/en/9.x/reference/cordova-plugin-file/#ios-quirks

cordova.file.* properties defined for iOS applicationDirectory and applicationStorageDirectory are read-only.

But for attaching files you demand

cordova.plugins.email.open({
    attachments: [
        'app://databases/db.db3' //=> /Applications/<AppName.app>/databases/db.db3 (iOS, OSX)
    ]
});

which make reference to application directory

How do I attach dynamic created files in iOS if I can't move files to application Directory?

How do you attach files in iOS?

jfoclpf commented 3 years ago

I had to convert to base64

window.resolveLocalFileSystemURL(imageUri, function (fileEntry) {
  fileEntry.file((file) => {
    if (!file.size) { console.error('File is empty (on fileEntry from resolveLocalFileSystemURL)'); return }
    var reader = new FileReader()
    reader.onloadend = () => {
      const base64 = 'base64:photo.jpg//` + reader.result.split(',').pop()' 
      console.log(base64)
    }
    reader.onerror = (err) => { console.error('Error on FileReader', err) }
    reader.readAsDataURL(file)
  }, (err) => { console.error('Error on fileEntry.file', err) })
}, (err) => { console.error('Error on resolveLocalFileSystemURL', err) })