pwlin / cordova-plugin-file-opener2 Goto Github PK
View Code? Open in Web Editor NEWA File Opener Plugin for Cordova
License: MIT License
A File Opener Plugin for Cordova
License: MIT License
How should i make to open popup view from bottom of ipad
It would be nice if you included a simple index page that users can see how to get this to work, I've spent many hours trying to get this to work but have been unsuccessful (phonegap n00b here).
Something simple like this: https://github.com/triceam/phonegap-plugins/blob/master/iOS/ExternalFileUtil/sample/www/index.html which is what I've been using just to get an idea how the plugin works.
Thanks.
Hi,
what are the supported formats that can be opened using the plugin, is it expected to work for all common file formats as long as we pass the right mime type?
Please test this plugin initially and tell me if something doesn't work. Thanks very much.
Where can I find a list of all error status codes? I'm trying to build in proper error handling.
When open a PDF file, iOS gives you an option to copy to PDF viewer but it just does nothing. The only option it works on iOS 9 is to use iMessage which will attach the PDF file, but texting with huge file attachment costly, instead, email option would work but it just uses the file name, not the real file.
Not sure if this plugin can force attachment email or force file to be opened with iOS 9.
Note that iOS <9 will open the file.
Wp8 - doesn't work in phonegap build
Is it possible to open files from the location 'data/data/app-id/files' (i used the contentsync plugin to download a PDF) or do i have to copy the files to '/storage/emulated/0/'? Thx
my application generate a PDF file and try to open it in adobe reader, it did work for the first time, but if i press the button "back to my app" from adobe reader to my application, regenerate the PDF again and try to open it for the second time, the plugin crashes, here are the logs:
Warning: Attempt to present <_UIDocumentActivityViewController: 0x13e955800> on <MainViewController: 0x13e538130> which is already presenting <_UIDocumentActivityViewController: 0x13e835400>
Assertion failure in -[_UIOpenWithAppActivity performActivity], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.29.5/UIDocumentInteractionController.m:408
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDocumentInteractionController has gone away prematurely!'
First throw call stack:
(0x1837a0f48 0x1982eff80 0x1837a0e18 0x184694a1c 0x1893b2fe4 0x1895db320 0x189088ba4 0x18908bd9c 0x188e63668 0x188d6f240 0x188d6ed3c 0x188d6ebc4 0x188535c2c 0x10018dc68 0x100193710 0x1837581f8 0x183756060 0x183684ca0 0x18e6ec088 0x188d9cffc 0x1000bff24 0x198b328b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
tested on iOS 9.1 using the master branch of plugin
I'm using fileOpener2.open on iOS, and it's working for some files, but when there's a space in the filename it doesn't open.
I tried putting my file URL through decodeURI before sending it to fileOpener2, but that did not help.
I haven't tried other characters that might get escaped in file URLs, like brackets or unicode.
it would be great if the plugin accepts cdvfile:// paths.
Hi
With iOs9 Apple has introduced mechanisms to not just open, but also edit files. I have searched a Codrova plugin that would provide this new way but have not found anything so far.
Do you have plans to change the file opener so it supports editing files?
Apple has provided me with information about what they call Document Provider
https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/FileProvider.html
Thank you for the great plugin
Simon
I'm having an issue when trying to open a .tiff file on Windows 10 platform.
mime type = "image/tiff".
filename is "test.tiff".
when calling cordova.plugins.fileOpener2.open, enters in error (e) callback, but without parameter (e is undefined).
However, if I renominate the filename to "test.undefined", it opens, asking me for a software to open that extension.
Any clue why is not opening this type of files?
regards
When trying to open a file I get this error in Android Studio:
Activity not found: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/sdcard/Android/data/io.cordova.myapp62c59d/files/test.pdf typ=application/pdf flg=0x4000000 }
Possible fix shown here.
When I am trying to open an image file from IOS using $cordovaFileOpener2.open it shows sharing options on ios (Message, Mail, Notes, iCloud Photo Sharing, Save to PDF to iBooks and more). And When i share file on eg. Message it show download file as attachment but it is not directly opening the file in Photo Viewer.
First I am downloading the file from server by using $cordovaFileTransfer.download after this I trying to open the same file $cordovaFileOpener2.open. In ios it start showing sharing options but in android it works perfectly.
I am testing on iOS 9.0.2
Please help.
Thanks
I get 404 Not Found error when I tried to install the file-opener2 plugin via the cordova CLI.
When I open an apk file, the screen become black for a while after installing. but I open the apk directly, not via the plugin, everything is OK. I hope installed an app then I can see the application installed page, then I can choose Done or Open button as usual (not screen black).
And I found the apk installed success even the screen is black.
Thank you.
I am trying to call this plugin and it works fine from webview. but it doesn't show up if inappwebbrowser is open.
hi i want to open a image in default image viewer which can give me proper zoom in and out and also maintain the image quality .
it is possible to open image with this plugin
I receive only data URI's form the server. And I can't find a way to open them. Does it support dataURL's
I only get this error when trying to open the url (it is a pdf)
11-19 11:33:48.571: W/PluginManager(30070): THREAD WARNING: exec() call to FileOpener2.open blocked the main thread for 135ms. Plugin should use CordovaInterface.getThreadPool().
I am using this file opener plugin for my phonegap application. PDF file is opened in android devices but in ios the file is not opened but alert show file opened successfully.
var fileName = "file:///storage/emulated/0/sample/one/test.pdf";
if(device.platform == "ios"){
var iosDirectory = "file:///var/mobile/Containers/Data/Application/EC83E4C-338B-48BA-AE4974F6A407D2A0/Documents/";
fileName = iosDirectory+"sample/one/test.pdf";
}
cordova.plugins.fileOpener2.open(fileName,
'application/pdf',
{
error : function(e) {
alert('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
alert('file opened successfully');
}
}
);
Please guide me to solve this issue.
the contentType argument to fileOpener2.open
is a MIME type under Android and a UTI under iOS.
The iOS implementation will try to guess the content type by the file extension* and the Android docs for Intent say overriding the detected type should "very rarely be used"*, so it is probably best for a cross-platform app to not attempt to specify this value at all.
(Unless fileOpener2 is able to provide a consistent mapping from MIME types to UTIs.)
When I open a PDF I am asked which application to use. If I choose iBooks it opens iBooks and I can view my PDF. In case I choose Mail in order to send an e-mail with the PDF attached it doesn't do anything. It doesn't even open the Mail app.
I tried file opener 2 in version 1.0.11 and I have an iPhone 6 running iOS 8.0 (12A365).
Is that a normal behaviour or do you reckon that it is related to this plugin?
I am deploying the same app on both the iOS and android platform. The app requires opening of locally stored PDF files. Since android does not allow the native PDF application to access the private app storage, I used asset2sd to copy the PDF from the asset folder onto the SD card and used cordovaFileOpener2 to open the file on the SD card. This works fine.
asset2sd.copyFile({
asset_file: path,
destination_file: "myapp/" + path
},
function() {},
function(err) { console.log('An error occurred: ' + JSON.stringify(err));}
);
$cordovaFileOpener2.open(
'/sdcard/myapp/' + path,
'application/pdf'
).then(function() {
console.log('Success');
}, function(err) {
console.log('An error occurred: ' + JSON.stringify(err));
});
My questions is how will this work on iOS given that iOS devices do not have an SD card. Is it possible to have the same code work on both platforms?
Hi,
it would be great, if you could add an additional method to check, whether there is any app installed, which can open a file by mimetype. E.g. like "canOpenFile(...)" in "Smile-SA/cordova-plugin-fileopener".
Big thx for this plugin, it helped me a lot!
hi @pwlin
according to this
https://build.phonegap.com/plugins/717
https://github.com/break24/cordova-plugin-file-opener2/blob/adff6addb80467e8f359a722cd62f0d1ce462e55/README.md
it seem the plugin almost a fork one from yours
because of it's example code look like as same as yours
in the author webpage that seem have no email address
so I can't get in touch with him
welljust want to see and ask you this
Hi. This is my fileOpener2 function:
cordova.plugins.fileOpener2.open(
url,
'application/pdf',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
where 'url' is a variable containing a dataurl. The format of that is:
data:application/pdf;base64,JVBERi0xLjMKJf////8KN .......
but it doesn't appear the "open with" popup. But if i insert a web url, it works.
Is the library don't supporting dataurl? Is there a way to solve this?
Thank you!
I installed this plugin and tried to open a pdf document located in img folder inside the www folder.
Here is my code
document.addEventListener("deviceready", function(){
$("#readfile").on("click", function(){
var source = buildAssetsUrl("img/lazy.pdf");
cordova.plugins.fileOpener2.open(
source,
'application/pdf',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
});
});
//methods
var baseUrl = location.href.replace("/index.html", "");
function buildAssetsUrl(file) {
return baseUrl + "/" + file;
}
Anything I did wrong?
Been trying to get this working for a bit now and am stumped. Files do not open but I also do not get an error or anything, nothing happens at all. I've got the event writing to the console and it appears to be firing correctly but I get neither a success or failure message. I've got this same basic case for multiple file types (pdf, doc, etc.) based on extension and none of them work.
case 'rtf':
cordova.plugins.fileOpener2.open(fullPath, 'application/rtf', {
error : function(errorObj) {
console.log('error - ' + errorObj.status + ' - ' + errorObj.message);
},
success : function () {
console.log('sucess');
}
});
break;
Please add an explanation to the readme of why this is a different repo from the other one in your account (cordova-plugin-file-opener).
Is one stable, and one unstable? Why did development stop on the first one?
Hello!
First of all, thank you so much for this awesome plugin. I have been using it since 2014.
The plugin fails on iOS 9, but it works perfectly in iOS 8 (even though files with special character names in them fail as well). I wanted to know if you plan to take a look into this, or if I can help with getting iOS 9 support for this plugin.
Thank you so much!
Is it possible to open a file without pass content type as parameter?
Hi Good Day Everyone, I'm using fileopener2 version 2.0.2.If the filename consist of spaces it shows an error: file not found.Can someone give me an idea to fix this error? Thank you.
@Gillardo
I need to open "app chooser"
not default application
Is it possible on wp8?
your code only open a default application
Windows.System.Launcher.LaunchFileAsync(file);
https://github.com/pwlin/cordova-plugin-file-opener2/blob/master/src/wp8/FileOpener2.cs#L29
Hello,
I am working on a project and used the earlier version of this plugin within the developed App. All worked fine.
Because our customer updated some iPads to iOS9 I was testing this upgraded plugin, but on iOS8 it doesnot work anymore? The App loses focus and the 'Home page' of the iPad is shown. Am I forgetting something? Maybe I need to change something in the configuration?
I am not sure it works on iOS9, I did not test that yet.
Hi, first off, we have been using this plugin for quite some time with great success so far 👍
However, we have recently upgraded our WP8.0 project to WP8.1 and it stopped working. The plugin can find the file on the device, that's working, but then in src/wp8/FileOpener2.cs
line 29
:
await Windows.System.Launcher.LaunchFileAsync(file);
it crashes with
COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
Can you please test with a WP8.1 project and try to fix it? Thanks!
This is called as soon as the menu is opened - not when the file has been opened.
This makes it hard to clean up files, but also to know if a file was really opened or not.
Would it be possible to use UIDocumentInteractionControllerDelegate to get more information about what happened during the callout?
This could also be used to give more informative error conditions.
Is it happen only to me?
The app continuously crashing during file opening.
I made this change in Plugins/FileOpener2.m as described in this comment:
http://stackoverflow.com/questions/22780691/correct-file-path-in-fileopener2-phonegap-cordova-plugin-for-ios/22959881#22959881
Now, the app is not crashing but in case of no file downloaded, fail() response doesn't works and nothing happen. Obviously I cannot use the patch from that page, building the app with online service of Adobe.
Below the debug log of the crash over my iOS Simulator 7.1 (11D167), I have not any real iPhone or iPad at moment for the testing.
https://www.dropbox.com/s/8hyg3jbqmqymivf/MExT%20PST_2014-04-27-183333_Rocco-MacBook-Air.crash
Hope that someone can help me :( i'm going crazy.
Hi,
I have created a cordova based hybrid application for Windows 8.1 platform with fileopener2 plugin added. I am using Visual 2013 Update 4 IDE for development and testing. I have my image saved locally on device say "C:/image.jpg".
I have used following code to open the file:
try {
cordova.plugins.fileOpener2.open(
'C://image.jpg',
'application/jpg',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
}
catch(e) {
console.log(e);
}
I am not able to see any errors and the image is also not displayed.
Any help will be much appreciated.
Thanks,
Chirag.
Hello,
your plugin is nice and works well with pdf, if it not contains spaces (like "hello tom.pdf")...
Can you extend the plugin that it works with spaces too?
And another question:
Does this plugin work with jpg, png, txt as well?
Thank you very much.
Is it possible to open an powerpoint presentation?
For example:
cordova.plugins.fileOpener2.open(
'/sdcard/Download/starwars.pptx',
'WHAT SHOULD BE HERE',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
The new build 2.0.0 causes applications to crash in IOS 9.0.1 if you use regular cdvfile:// instead of file:/// urls
Using your plugin has been almost effortless on both Android and iOS, so thanks for that. I was wondering if it is possible to set the dialog position on an iPad. At the moment it shows about halfway up the screen (in portrait), but it would be very nice if I could position it so it lines up with the GUI widget that triggers it. Is this possible?
I can't open files after update to iOS9
plugin not working anymore.
@pwlin any solution for iOS9?
Thanks!
Whenever I want to open a pdf file, the "Open File in.." dialog asks me the app I want to use. Adobe Reader or Quickoffice? I cannot set anyone as the default. It would be great if we can set the default program for each content type.
Hello,
Using io.github.pwlin.cordova.plugins.fileopener2, I can't open my local PDF file in Android.
Locally, I have a "/myapp/www/pdf/" folder with files (1.pdf,... to 6.pdf).
Here my PhoneGap config.xml
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="app.example.com" version="1.0.0">
<name><![CDATA[Example]]></name>
<description>...</description>
<author href="http://www.example.com" email="[email protected]">Example</author>
<content src="index.html"/>
<preference name="permissions" value="none"/>
<preference name="orientation" value="default"/>
<preference name="target-device" value="universal"/>
<preference name="fullscreen" value="true"/>
<preference name="webviewbounce" value="false"/>
<preference name="prerendered-icon" value="true"/>
<preference name="stay-in-webview" value="false"/>
<preference name="ios-statusbarstyle" value="black-opaque"/>
<preference name="detect-data-types" value="true"/>
<preference name="exit-on-suspend" value="false"/>
<preference name="show-splash-screen-spinner" value="true"/>
<preference name="auto-hide-splash-screen" value="true"/>
<preference name="disable-cursor" value="false"/>
<preference name="android-minSdkVersion" value="7"/>
<preference name="android-installLocation" value="auto"/>
<preference name="useBrowserHistory" value="true" />
<gap:plugin name="org.apache.cordova.console"/>
<gap:plugin name="org.apache.cordova.device"/>
<gap:plugin name="org.apache.cordova.dialogs"/>
<gap:plugin name="org.apache.cordova.file"/>
<gap:plugin name="org.apache.cordova.file-transfer"/>
<gap:plugin name="org.apache.cordova.inappbrowser"/>
<gap:plugin name="org.apache.cordova.network-information"/>
<gap:plugin name="io.github.pwlin.cordova.plugins.fileopener2" version="1.0.11" />
<icon src="icon.png"/>
<icon src="res/icon/android/icon-36-ldpi.png" gap:platform="android" gap:qualifier="ldpi"/>
<icon src="res/icon/android/icon-48-mdpi.png" gap:platform="android" gap:qualifier="mdpi"/>
<icon src="res/icon/android/icon-72-hdpi.png" gap:platform="android" gap:qualifier="hdpi"/>
<icon src="res/icon/android/icon-96-xhdpi.png" gap:platform="android" gap:qualifier="xhdpi"/>
<icon src="res/icon/ios/icon-57.png" gap:platform="ios" width="57" height="57"/>
<icon src="res/icon/ios/icon-72.png" gap:platform="ios" width="72" height="72"/>
<icon src="res/icon/ios/icon-57-2x.png" gap:platform="ios" width="114" height="114"/>
<icon src="res/icon/ios/icon-72-2x.png" gap:platform="ios" width="144" height="144"/>
<gap:splash src="res/screen/android/screen-ldpi-portrait.png" gap:platform="android" gap:qualifier="port-ldpi"/>
<gap:splash src="res/screen/android/screen-mdpi-portrait.png" gap:platform="android" gap:qualifier="port-mdpi"/>
<gap:splash src="res/screen/android/screen-hdpi-portrait.png" gap:platform="android" gap:qualifier="port-hdpi"/>
<gap:splash src="res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:qualifier="port-xhdpi"/>
<gap:splash src="res/screen/ios/screen-iphone-portrait.png" gap:platform="ios" width="320" height="480"/>
<gap:splash src="res/screen/ios/screen-iphone-portrait-2x.png" gap:platform="ios" width="640" height="960"/>
<gap:splash src="res/screen/ios/screen-iphone-portrait-568h-2x.png" gap:platform="ios" width="640" height="1136"/>
<gap:splash src="res/screen/ios/screen-ipad-portrait.png" gap:platform="ios" width="768" height="1024"/>
<gap:splash src="res/screen/ios/screen-ipad-landscape.png" gap:platform="ios" width="1024" height="768"/>
<access origin="*"/>
<plugin name="cordova-plugin-whitelist" version="1"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>
<platform name="android">
<allow-intent href="market:*"/>
</platform>
<platform name="ios">
<allow-intent href="itms:*"/>
<allow-intent href="itms-apps:*"/>
</platform>
<feature name="http://api.phonegap.com/1.0/file"/>
</widget>
I already tried many things like that in my html files :
<!-- openPDF is a personnal function... see next block -->
<a onClick="openPDF('pdf/1.pdf');">Open PDF</a>
My functions (js files) :
var fs;
function fsSuccess(fileSystem)
{
fs = fileSystem;
}
function fsFail(event)
{
console.log(event.target.error.code);
}
function openPDF(file) {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, fsSuccess, fsFail);
file = fs.root.toURL() + file;
cordova.plugins.fileOpener2.open(
file, // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
'application/pdf',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
$('#errorpdf').html('Error status: ' + e.status + ' - Error message: ' + e.message+' - File : '+file);
},
success : function () {
console.log('file opened successfully');
$('#errorpdf').html('file opened successfully');
}
}
);
}
All the time, Cordova returns me : "Error status: 9 - Error message: File not found"
Where am I wrong ?
EDIT : my folders
/storage/emulated/0/Android/data/com.example.app/files
/storage/emulated/0/Android/data/com.example.app/cache
obviously is empty and I don't know how to move local .pdf file to this folder.
Do you have plans of adding this plugin to npm in the near future?
Hi all, after mucking around for many hours, i thought I would attempt to document working examples for all three platforms, as well as suggest resolutions that will make the plugin work more consistently across platforms.
The following example uses the cordova-plugin-file to write some binary data to the system and then open it with this plugin.
Writing a binary blob with file:
cordova.writeBinaryToLocalFile = function (binaryBlob, fileName, onSuccess){
fileName = cordova.replaceFileNameSpacesWithUnderscoresToAvoidErrors(fileName);
var createWriterCallback = function(fileWriter){
fileWriter.onwriteend = onSuccess;
fileWriter.write(binaryBlob);
};
var getFileCallback = function(file){
file.createWriter(createWriterCallback);
};
var requestFileSystemCallback = function(fileSystem){
fileSystem.root.getFile(fileName, { create: true }, getFileCallback);
};
window.requestFileSystem(window.TEMPORARY, 50 * 1024 * 1024, requestFileSystemCallback);
};
Shared Functions:
cordova.replaceFileNameSpacesWithUnderscoresToAvoidErrors = function(fileName){
return fileName.split(" ").join("_");
}
Windows 8.1 (Metro App on Desktop):
cordova.openLocalFile = function (fileName) {
fileName = cordova.replaceFileNameSpacesWithUnderscoresToAvoidErrors(fileName);
var folder = Windows.Storage.ApplicationData.current.temporaryFolder;
//folder.path = C:\Users\<user>\AppData\Local\Packages\<your package>
cordova.plugins.fileOpener2.open(folder.path + '\\' + fileName, null);
};
Android App:
cordova.openLocalFile = function (fileName) {
fileName = cordova.replaceFileNameSpacesWithUnderscoresToAvoidErrors(fileName);
//cordova.file.externalCacheDirectory = file:///storage/emulated/0/Android/data/<your package name>/cache/
var nativeUrl = cordova.file.externalCacheDirectory + fileName,
fileArray = nativeUrl.split('.'),
extension = fileArray[fileArray.length - 1],
mimeType = null;
switch (extension) {
case 'jpg':
case 'jpeg':
case 'png':
case 'tiff':
case 'gif':
case 'bmp':
mimeType = 'image/*';
break;
case 'xlsx':
case 'xls':
case 'csv':
case 'doc':
case 'docx':
case 'rtf':
case 'xml':
mimeType = 'application/*';
break;
case 'pdf':
mimeType = 'application/pdf';
break;
case 'html':
mimeType = 'text/web';
break;
default:
mimeType = '*/*';
break;
}
cordova.plugins.fileOpener2.open(nativeUrl, mimeType);
};
IOS App:
cordova.openLocalFile = function (fileName) {
fileName = cordova.replaceFileNameSpacesWithUnderscoresToAvoidErrors(fileName);
//cordova.file.applicationStorageDirectory = file:///var/mobile/Applications/<Your unique app number>/
var nativeUrl = (cordova.file.applicationStorageDirectory + "tmp/" + fileName).substring(7);
cordova.plugins.fileOpener2.open(nativeUrl);
};
Calling Code:
cordova.writeBinaryToLocalFile(data, fileName, cordova.openLocalFile.bind(null, fileName));
Overall Issues:
There's alot of conditionals to be done with this application (granted because each application platform has a different file system). However,
I love the plugin, and will continue to use it. Just wanted to document this for future users, as current documentation and issues tend to be scarce on this plugin.
Happy hunting!
I am using Apache Cordova in Visual Studion 2015 and running the project as WIndows project.
In the app, I download pdf file and then try to open it using
cordova.plugins.fileOpener2.open(
options.filePath,
options.fileType,
{
success: function () {
console.log('[DEBUG] file opened successfully');
},
error: function (error) {
console.log('[ERROR] status: ' + error.status + ' - Error message: ' + error.message);
}
}
);
where options.filePath is 'ms-appdata:///local//cache.pdf'
and options.fileType is 'application/pdf'
However i get :
Exception is about to be caught by JavaScript library code at line 49,
column 14 in ms-appx-web://<package_name>/www/plugins/cordova-plugin-file-opener2/src/windows/fileOpener2Proxy.js
0x80070057 - JavaScript runtime error: The parameter is incorrect.
Any ideas what can be wrong with my parameters?
Thanks
I created a temp file "temp.pdf" under cordova.file.cacheDirectory and need to open it after it is created. I don't know which kind of file path of cordova.file.cacheDirectory can be accepted by fileOpener2.open. Here is my code.
private openFile(fileName, contentType) {
var pathToFile = cordova.file.cacheDirectory + fileName;
window.resolveLocalFileSystemURI(pathToFile, (fileEntry: FileEntry) => {
var filePath = fileEntry.toURL().substring(8);
// var filePath = fileEntry.fullPath;
(<ICordovaPlugins>window.cordova.plugins).fileOpener2.open(filePath, contentType, {
error: (errorObj: any) => {
console.log("Cannot open file, failed to open the temporary file: " + errorObj.status + ': ' + errorObj.message);
},
success: () => {
console.log(fileEntry.fullPath);
}
})
},
() => {
console.log("Cannot open file, failed to get cache directory.");
}
);
}
To open a file under cordova.file.cacheDirectory, which path does fileOpener2.open expect?
(1) For fileEntry.toURL(), I got "file:///data/data/AppID*****/cache/temp.pdf"
(2) For fileEntry.fullPath, I got "/temp.pdf"
(3) For fileEntry.toInternalURL(), I got "cdvfile://localhost/cache/temp.pdf"
I have tired all of the paths above, none of them can open the temp file which was created successfully. Is cordova.file.cacheDirectory an internal location rather than an external location so that the file cannot be open from this location using fileOpener2?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.