I have a very critical problem.
I'm developing mobile app on android and iOS using apahce cordova with visual studio 2015.
My app downloads and opens a pdf file from external direct url using file transfer and file opener plugins.
I've successfully downloaded and opened that file on android on device memory.
but no matter how many time i try to do the same thing on iOS , it never works.
I have tried all directories on that link : https://github.com/apache/cordova-plugin-file#where-to-store-files
All i want is a working example of downloading a file in any directory from external server and open it in iOS using apache cordova.
thank you in advance.
I recently had the same problem to solve, and used the file opener 2 plugin, which you use like this:
cordova.plugins.fileOpener2.open(
'path/to/file.pdf',
'application/pdf',
{
error: function(e) {
console.log('Error opening file:' + e);
console.log('path: ' + filePathAndroid);
},
success: function() {
console.log('File opened successfully');
console.log('path: ' + filePathAndroid);
}
}
);
This opens the PDF using an action sheet that shows all the possibilities that the device has for handling it (Adobe Reader if installed, iBooks, AirPrint, send to email etc).
You can use the Cordova file plugin to download the PDF from your server and work out a path to it on the local device.
My sample app that shows a range of ways of handling PDFs for Android and iOS can be found here. There I tried the In App Browser (not great, doesn't work on Android), PDF.js (renders PDF inline in a canvas, but pretty slow and no pinch zoom) and the file opener 2 plugin (most "natural" way to use the device's abilities in my opinion).
Raymond Camden also recently blogged on this subject, you may find his post useful background reading too.
Related
I have a Website(ReactJs) with a pdf download functionality(via base64) and it works fine. For Android, I have a cordova app where the app is pointed to website and no actual app code resides inside cordova and this is where the problem starts.
The PDF download is not working in app and I have been restricted from using native java code or Cordova(js + file-plugin).
Is there any way to achieve this with given constraints?
My website creates "presigned-url" to download files from Amazon S3.
In Desktop and Android this URL starts download perfectly using Chrome or other browser.
https://s3.sa-east-1.amazonaws.com/videos.cinemedsite.com.br/888888/888888_00000000000_20180808_235040.mp4?AWSAccessKeyId=AKIAJQCURENNFPNNGK6A&Expires=1609383840&Signature=4lYLxgkAIt3xMer%2FPcL%2FAepwbkY%3D
But with this same URL on iOS (iPad and iPhone tested), the video just plays in any browser and there's no way to download.
I've tried to download directly from aws console too, no success.
Metadata is already configured as :
content-disposition: attachment;filename=lixo.mp4
content-type: video/mp4 (already tried application/octet-stream also).
Any ideas ?
Thanks in advance!
Marcello
On iOS there is not a user accesable file systems with default download 'folder' as you have on a PC or MAC - i.e. you can't just click a link in the browser and have the file download to it.
With Apps like dropbox you van open a PDF file, for example, in your browser and then click the Share button and choose Dropbox to download to your device. 'Documents', another app available on the appstore, has a built in browser so is worth looking at also.
You can create your own application which will accept a URL, download it and then provide a list or directory of downloaded files. These files will only be visible by the app unless you add some functionality to save them to, for example, the gallery.
There is an AWS SDK available on Github which would be a good place to start if you are using your own app: https://github.com/awslabs/aws-sdk-ios-samples
This is just for the record, since I found the solution.
I experienced an Issue happening only on PWA Standalone App on Androïd device.
I used to open PDF file from my standalone VueJs application with this code :
window.open('<PDF FILE URL>')
or
window.open('<PDF FILE URL>', '_blank')
In that case, the PDF couldn't be read on Android Device. I had this message
Impossible d'afficher le PDF/d'ouvrir
I guess that in english error message would be something like :
Cannot display PDF/Open
Note that in the other side
It works on standard browser (Chrome, Firefox, Internet Explorer)
It works on Apple Device (as PWA)
it works on Windows App (as PWA)
I doesn't work on Android as PWA
My solution was to simply change my code with :
window.location = '<PDF FILE URL>'
My solution was to simply change my code with :
window.location = '<PDF FILE URL>'
I am trying to download a pdf file using an ASP.Net MVC web application however have noticed that it always fails to download both 1) the file and 2) fail to open up the file within the browser.
Note: The link does not point to a URL + filename with a .pdf extension...it directs to a controller/action that should return the pdf.
All the correct content types/MIME types have been setup correctly:
pdf: application/PDF
ppt: application/vnd.openxmlformats-officedocument.presentationml.presentation
xlsx: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
...just not sure why it doesn't work.
Can anyone shed any light on this please.
What I would like to achieve is either viewing the file within the browser or downloading the file to the phone to view.
Note: Seems to work perfectly well on ios mobile safari browser, and all desktop browsers!
Note 2: the actual error message in the notification area in Android is:
< Untitled >
Download unsuccessful.
I need to open a pdf in a hybrid app, the pdf is previously downloaded by the hybrid app (the app has both read and write from external storage). I can retrieve via fileSystem the file entry:
someDirEntry.getFile(fileName, {create: true, exclusive: false}, openViewPdf, ioFail);
in openViewPdf I can read the path of the file:
function openViewPdf(fe){
console.log("V1 "+fe.toURL());
console.log("V2 "+fe.fullPath);
//console.error("V3 "+toNativeURL()); //not supported by 2.3.0
window.open(fe.toURL(), '_system');
}
the output is something like:
V1 file:///mnt/sdcard/someDir/fileName.pdf
V2 file:///mnt/sdcard/someDir/fileName.pdf
i.e. there is no difference between fullpath and .toURL(). A new window opens, but in the new window I see an error alert:
There was a network error. (file:///android_asset/www/fileName.pdf
It's like the InAppBrowser tries to open the pdf in the asset directory of the app (which of course is wrong!) the proper path is the ones listed above. Isn't there any way of making this work other than trying the extra plugin (see: Phonegap how to download and open pdf file in android app)?
After plenty of work the answer is: "No, there is no way of opening a pdf with InAppBrowser in Android". The upside is that the plugin is easy to do in java.