Comments (49)
For future reference, I could resolve it by decoding the url.
var documentURL = decodeURIComponent("file:///storage/emulated/0/Documents/My%20Learnings%20during%20the%20program.docx");
from cordova-plugin-file-opener2.
I am trying to open a word document in android using FileOpener2 plugin version 1.0.11
This is my code
var documentURL = "file:///storage/emulated/0/Documents/My%20Learnings%20during%20the%20program.docx"; // This is how cordova FileSystem returns the url (toURL()) when there are spaces in the document name.
var contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
cordova.plugins.fileOpener2.open(
documentURL,
contentType, {
error: function (errorObj) {
console.log('Error status: ' + errorObj.status + ' - Error message: ' + errorObj.message);
},
success: function () {
}
}
);
and I get this error
Error status: 9 - Error message: File not found
from cordova-plugin-file-opener2.
it's 2017 July, I'm facing same problem in my android application. In my case I'm using cordova transfer plugin to download a file from server. Once downloaded the URI i,e returned from the transfer plugin is converted into native path via cordova file path plugin. That file path is passed as an argument to cordova file opener plugin. But it is working for the android version 6.0 and above but not working in android version 5.1.1.
from cordova-plugin-file-opener2.
Resolved!
Isn't your plugins problem, but my oversight in the code.
I download the pdf everytime user access. In this passage, i didn't override the path with the new one.
In android this doesn't make any difference, but in ios, apparently does.
Thank you for all your support and great plugin!
I hope this can be useful to other people!
from cordova-plugin-file-opener2.
Hi @keturn
This was a problem with older versions of this bug which supposedly is fixed in latest version (1.0.11)
.
Which version are you using?
from cordova-plugin-file-opener2.
I have version 1.0.11, it looks like I have had it since November 4th, and I reported this on November 14th. So yes, I believe I was working with 1.0.11 during this time.
from cordova-plugin-file-opener2.
Can you show me an example of how you pass the file path? Is the file path an URI?
from cordova-plugin-file-opener2.
@krishtc great that you find an solution and thanks for posting it here!
from cordova-plugin-file-opener2.
This still appears to be a bug in 1.0.11. Tested on Android; krishtc's fix successfully resolves the issue.
from cordova-plugin-file-opener2.
As we are already passing file URL encoded I just removed stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding in the file FileOpener2.m and it now opens any file just fine. I've tested files with spaces in their name and special characters as well.
NSString *path = [[command.arguments objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Is replaced with :
NSString *path = [command.arguments objectAtIndex:0];
from cordova-plugin-file-opener2.
This has been causing me some pain too. I've updated keturn's pull request to merge cleanly with the current master. Without this, the plugin requires different filename encoding on Android and iOS.
from cordova-plugin-file-opener2.
Please test this bug again and let me know if @guyc 's PR fixed this issue.
from cordova-plugin-file-opener2.
Having the same issues with version 2.0.2 that fileURIs with spaces do not work on iOS.
In my case the fileURI is already url decode (ie. no %20 in file URI)
Unfortuntately, I am using phonegap build so I'm not able to test directly if @guyc fix works.
(or is there a way to have dev builds in npm?)
this._fileURI is "file:///var/mobile/Containers/Data/Application//Documents/test/Test cordova 52.jpg"
I get a "File does not exist" status 9 error
Was working before I upgraded from cordova 3.6.3 to cordova 5.20. Assume this is since I changed version of the plugin cordova-plugin-file-opener2 from 2.0.1 to 2.0.2 (so reverting to 2.0.1 ought to work for me)
Code I am using
log.info("Opening file "+ this._fileURI + " with mime " + this._mimeType)
var that = this;
cordova.plugins.fileOpener2.open(
this._fileURI,
this._mimeType,
{
error : function(e) {
log.error("Failed to open file");
log.error(e);
that._reportWarningToUser("Fil kan ikke vises på din telefon.");
},
success : function () {
log.info("file opened successfully");
that._reportInformationToUser("Fil skal nå åpnes i annen app.");
}
}
);
from cordova-plugin-file-opener2.
Experiencing the same issue here on Phonegap 6.4.0, iOS 10.2.1. Have tried applying encodeURI to the path, doesn't help.
from cordova-plugin-file-opener2.
@WeaponX86: this Stack Overflow comment explains exactly how you can use HTML5 File System APIs to download and save a file locally.
So all you really have to do is simply:
- Download the file
- Save it in the device without any spaces in the name
- Open it with file-opener2
from cordova-plugin-file-opener2.
The file is already saved locally...I write them to cordova.files.documentsDirectory. If the filename has spaces your plugin won't open them.
from cordova-plugin-file-opener2.
But why the file has spaces? Can't you save it with a name which does not have spaces in it?
from cordova-plugin-file-opener2.
That doesn't help for the thousands of files already distributed to clients in the field.
from cordova-plugin-file-opener2.
I'm sorry, I vaguely remember fixing an issue like this in 2016 or 2015, but I don't have an iDevice to test it anymore. I will get back to it as soon as i get an opportunity.
from cordova-plugin-file-opener2.
Thank you, your work is appreciated.
from cordova-plugin-file-opener2.
You are welcome. Your use case is a bit extreme, but in standard situations I always advise people to clean up the file name, re-save it, and open the modified version.
from cordova-plugin-file-opener2.
There has been a couple of new releases since then. Can you please upgrade and test if you still have issues? thanks
from cordova-plugin-file-opener2.
Hi, i have the same issue.
I just update the plugin to version 2.0.13, but still have "Error status: 9 - Error message: File does not exist".
I'm trying to open an url like this "file:///var/mobile/Containers/Data/Application/D92D0A2D-06F9-42B5-A6BB-90B21C7150FF/Documents/14925300362961tbFn.pdf" made up with cordova.files.documentsDirectory in ios device.
I'm working with iOS 10.3.1.
Thank you in advance!
from cordova-plugin-file-opener2.
But this issue is about spaces in file names. your document does not have a space in it, right?
from cordova-plugin-file-opener2.
Oh, right. Should I create a new issue?
from cordova-plugin-file-opener2.
well it's ok, as long as I can help.
Can you try to open your pdf file with InAppBrowser plugin? Does that work?
from cordova-plugin-file-opener2.
I've already try it.
I have used window.open(path ,"_blank","location=no,enableViewportScale=yes").
It shows a blank screen and in log
webView:didFailLoadWithError - -1100: The requested URL was not found on this server.
I not understand why it's not working with your plugins and /or with inappbrowser.
Otherwise thank you for your support.
from cordova-plugin-file-opener2.
Can you post some code how you construct the path
? I think that's where the problem exists.
Also, InAppBrowser has a bigger community behind it and more people can help you. I think they even have a slack channel or something, (there is also #general channel at https://cordova.slack.com/ which you can ask all kinds of questions)
As soon as you get your path
up and running in InAppBrowser, you can use the same code for path
to open your file in FileOpener2
from cordova-plugin-file-opener2.
Great to see you solved your problem. Sometimes the solutions are far easier than we initially think 😺
from cordova-plugin-file-opener2.
Can someone please test to see if files containing spaces in their names work in iOS?
from cordova-plugin-file-opener2.
I just tried. I modified my file name with some spaces.
The file is saved with this path:
file:///var/mobile/Containers/Data/Application/D6CB427E-B5B0-4BEE-8177-9A3139E7697B/Library/NoCloud/1492604709345GP3NE test.pdf
Modified by plugin, it becomes like this:
file:///var/mobile/Containers/Data/Application/D6CB427E-B5B0-4BEE-8177-9A3139E7697B/Library/NoCloud/1492604709345GP3NE%20test.pdf
In this case it returns
"Error status: 9 - Error message: File does not exist"
It's like it doesn't see the transformation of the blank space in "%20".
I hope this can be helpful for you.
from cordova-plugin-file-opener2.
Ok thank you for being the bearer of bad news 🤣
I leave this issue open for now and will see how can we fix this.
from cordova-plugin-file-opener2.
Getting "File does not exist" for ios version 2.0.19
from cordova-plugin-file-opener2.
This plugin still has an issue on iOS opening files with spaces.
In my case, it's because the filename is being percent-encoded twice.
I.e. if you pass it file that has a space in it, but using a correctly encoded URL such as:
file:///Users/asgeo1/Library/Developer/CoreSimulator/Devices/68860C10-7A67-4A9B-802D-FA6489D7DF8C/data/Containers/Data/Application/2D6EE0BA-0BC2-465F-AD99-70E2CEDAD094/tmp/Adam%20test.pdf
It then re-encodes the %20
to %2520
:
file:///Users/asgeo1/Library/Developer/CoreSimulator/Devices/68860C10-7A67-4A9B-802D-FA6489D7DF8C/data/Containers/Data/Application/2D6EE0BA-0BC2-465F-AD99-70E2CEDAD094/tmp/Adam%2520test.pdf
Which breaks the URL. Now, what is even stranger, is that this issue was fixed way back in November 2015 with this Pull Request:
https://github.com/pwlin/cordova-plugin-file-opener2/pull/21/files
as it removed the call to stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
which is causing the double-encoding.
But then for some reason that fix was clobbered with this commit in April 2017:
which re-introduces the stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
call.
I don't have a problem with it encoding spaces to %20
, but it needs to do it in a way that doesn't double encode stuff. If it's easier, it would be better to not do any encoding at all, and force the user to provide a correctly formatted URL.
from cordova-plugin-file-opener2.
Getting "File does not exist" for ios version 2.0.19
I am also getting this error when i upgarded the plugin to 2.0.19 is there a solution to this issue
asgeo1 is right this was due to the space present in the file name which was causing the issue when the space was removed it works as expected but this was not the case before the update.
from cordova-plugin-file-opener2.
fix kindly supplied by https://github.com/JoxC has made its way to release 2.2.0
. Initial testing seems to confirm this has been fixed now. If there is still an issue please feel free to reopen the ticket.
from cordova-plugin-file-opener2.
I didn't have any issue with filenames containing spaces before this 2.2.0 update. Only with special characters like $
and #
on Android. But since this update files containing spaces do not open.
OSX: 10.14.3
Cordova: 8.1.2
cordova-ios: 5.0.0
cordova-android: 8.0.0
from cordova-plugin-file-opener2.
Same issue here on iOS. When will this issue be fixed? The application is affected in production... Is there a workaround meanwhile? Thanks in advance!
from cordova-plugin-file-opener2.
hi @rpanadero, can you provide a code snippet of how you guys are opening the file? thanks
from cordova-plugin-file-opener2.
@shnist I invoke the plugin like that
cordova.plugins.fileOpener2.open(
"file:///var/mobile/Containers/Data/Application/1486B27F-E34D-4169-BCDC-1880E4DB5AA4/Library/Caches/chat/Retencion de liquidos.pdf",
"application/pdf",
{
error : function(){ },
success : function(){ }
}
);
And after this line
NSURL *fileURL = [NSURL URLWithString:[path stringByRemovingPercentEncoding]];
Then, fileURL
is NULL, this log is thrown looking for file at (null)
and we see this error:
{
"message": "File does not exist",
"status": 9
}
I hope this helps you. Thanks!
from cordova-plugin-file-opener2.
@rpanadero thanks for sharing. Can I check something? The URL to that file in your code snippet, is that hard-coded? Or are you using the cordova file plugin? I'm pretty sure file://
doesn't work on iOS, but I may be wrong. My recommendation would always be to use the cordova file plugin to get the correct file paths.
from cordova-plugin-file-opener2.
@shnist The URL is hardcoded in the snipped because I wanted to show you with what params we invoke this plugin. However, in our application, the file URL is got by cordova file plugin
. In fact, the base URL is got by cordova.file.cacheDirectory
as you can guess.
The problem must be because the filename contains spaces, and it seems that the plugin doesn't deal with them correctly. Others files without spaces can be opened following the same application flow.
Feel free if you have more questions. Thanks!
from cordova-plugin-file-opener2.
OK, thanks for the clarification
from cordova-plugin-file-opener2.
@shnist were you able to have a look at this?
from cordova-plugin-file-opener2.
Apologies, I don't have much time to look into this issue at the moment, apart from looking closely at the previous attempts to fix it. I think we need to remove all the encoding logic for iOS so will test this out when I get a chance.
from cordova-plugin-file-opener2.
@shnist I have forked this plugin to fix the encoding issue on iOS, but I haven't had enough time to test my approach in different scenarios. If you want I can raise a pull request in order to test the change together.
from cordova-plugin-file-opener2.
@rpanadero yes please, that would be great.
from cordova-plugin-file-opener2.
@rpanadero I've published the fix from your PR in version 2.2.1
from cordova-plugin-file-opener2.
use this
replace(/[" "]/g, '%20')
from cordova-plugin-file-opener2.
Related Issues (20)
- FileOpener2 error in electron 11 HOT 1
- Plugin is not handling Cookies in React project HOT 1
- Add documentation for error codes
- USB PORT PARAM HOT 1
- doesnt work with IOS and assets-library
- Usage in Capacitor HOT 1
- pdf opened in an external app cannot save changes HOT 1
- Cannot open file while is at app data location '/data/data/<app_id>/cache' HOT 2
- unable to open application/pdf format in Android device (Samsung Galaxy S21 and Samsung Galaxy S21+) HOT 2
- android.support.v4.content.FileProvider not found HOT 7
- Relative URIs are not supported.
- remove: android.permission.REQUEST_INSTALL_PACKAGES from plugins.xml HOT 85
- Text Open file in always localized in english (Android) HOT 4
- There was a problem parsing the package for android install apk HOT 1
- Can't edit file HOT 2
- Getting error after updating plugin to 4.0.0 on Android Studio HOT 2
- Unable to open some MP4 files on iOS? HOT 1
- This plugin has a maintained forked repo now - please use and follow HOT 4
- Error: Current working directory is not a Cordova-based project.
- iPadOS not supported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cordova-plugin-file-opener2.