Search code examples
ioscordovafile-uploadcordova-plugins

How to upload a pdf from iphone using cordova?


I Have a requirement to upload a pdf/doc to server when i put <input type='file'> its only giving access to Gallery. I Know due to security reasons this will not allow to access other things but is their any other way to do this. If yes please help me to find the solution


Solution

  • On iOS 9, the input type file has access to "document providers", that means, if you have apps installed that can handle files (dropbox, drive, onedrive, etc), they will appear as options and once you choose it you can use an ajax call to send it to the server.

    If you want to support iOS 8 you can use my file picker plugin that will allow you to choose files from document providers And once the plugin retun the file url, you have to use cordova-plugin-file-transfer to send it to the server.

    window.FilePicker.pickFile(successCallback,errorCallback);
    

    On successCallback you'll get the file url

    If the .doc/.pdf is generated by your app and/or it in your app sandbox because you downloaded it previously, you can use the cordova-plugin-file to get the file url and then you can use the cordova-plugin-file-transfer plugin to upload it to the server too