j3k0 / cordova-plugin-openwith

Get your Cordova App in the O.S. "Share" menu on iOS and Android
MIT License
138 stars 114 forks source link

Description needs more clarity #90

Open fega opened 4 years ago

fega commented 4 years ago

Hello, thanks for your work in the plugin

I have seen multiple forks and issues related with the lack of support of more data types. as far I see there is not intention to add this kind of support to this plugin, so probably the correct thing to do is to specify in the description about it (that this plugin is only intended to support images), to avoid misleading ideas.

thanks

crapthings commented 4 years ago

i've tried share mp4, pdf from file manager on android, it works. havent try ios yet.

and when i click share on chrome menu it shares an image not url

import axios from 'axios'

const fileReaderSync = file => new Promise(resolve => {
  const reader = new FileReader()
  reader.onloadend = function () {
    var blob = new Blob([new Uint8Array(this.result)], { type: file.type })
    resolve(blob)
  }
  reader.readAsArrayBuffer(file)
})

const resolveLocalFileSystemURLSync = uri => new Promise(resolve => {
  window.resolveLocalFileSystemURL(uri, function (fileEntry) {
    fileEntry.file(resolve)
  })
})

Meteor.startup(function () {
  cordova.openwith.init(function () {
    cordova.openwith.addHandler(async function (intent) {
      const data = new FormData()

      if (intent.items.length > 0) {
        for (const item of intent.items) {
          const file = await resolveLocalFileSystemURLSync(item.uri)
          const blob = await fileReaderSync(file)
          data.append('files', blob)
        }

        axios({
          method: 'post',
          url: 'http://192.168.50.76:3000/api/upload',
          data,
          headers: {'Content-Type': 'multipart/form-data' }
        })
        .then(function (response) {
          alert(JSON.stringify(response, null, 2));
        })
        .catch(function (response) {
          alert(response);
        })
      }
    })
  }, function () {
    alert('failed')
  })
})

And i'm using meteor this is "mobile-config.js" that i added for this plugin

App.configurePlugin('cc.fovea.cordova.openwith', {
  ANDROID_MIME_TYPE: '*/*',
  IOS_URL_SCHEME: 'ccfoveaopenwithdemo',
  IOS_UNIFORM_TYPE_IDENTIFIER: 'public.image',
})