Reputation: 1097
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.
Upvotes: 4
Views: 2858
Reputation: 502
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.
Upvotes: 2
Reputation: 512
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
Upvotes: 0
Reputation: 546
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..
Upvotes: 1