4

Can I use navigator.camera.getPicture() in cordova api to select a pdf from device? my code is

navigator.camera.getPicture(fileUploadSuccess,fileUploadFail,
            {sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY, 
            destinationType:navigator.camera.DestinationType.DATA_URL,
            quality:50,mediaType:navigator.camera.MediaType.ALLMEDIA});

the code opens device gallery but i can see only image files. Do I need to change any options? Is there any alternative if I can't use camera.getPicture() method? I am using cordova as this is a hybrid app.

Arul Dinesh
  • 550
  • 4
  • 15
Shoreki
  • 1,057
  • 4
  • 14
  • 33

3 Answers3

2

Yes, you can. At least on Android with camera plugin v4.0.3

I'm using the folowing code

navigator.camera.getPicture(onSuccess, onFail, {
    sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
    mediaType:navigator.camera.MediaType.ALLMEDIA,
    destinationType: Camera.DestinationType.FILE_URI
});

And it let me select any files : pdf, docx...

It returns the file Uri, even if you use DATA_URL as the destinationType.

Djames
  • 462
  • 7
  • 14
1

No, You need to Use FileOpener Plugin for that Purpose...

I used this Link :- https://github.com/markeeftb/FileOpener

It also has a suggestion for its Use. This works For Me..

Akshay Tyagi
  • 528
  • 4
  • 7
0

You cann't open file using getPicture(), you can you file opener :

https://github.com/pwlin/cordova-plugin-file-opener2

you can refer this also: here

Community
  • 1
  • 1
Amar1989
  • 502
  • 1
  • 3
  • 17
  • He wants to select a file (to upload it for exemple), not to show it like file-opener2 does. – Djames Feb 18 '19 at 14:39