Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non ASCII characters in filename --> file not found #190

Open
polfdz opened this issue Jan 18, 2018 · 6 comments
Open

Non ASCII characters in filename --> file not found #190

polfdz opened this issue Jan 18, 2018 · 6 comments
Labels

Comments

@polfdz
Copy link

polfdz commented Jan 18, 2018

The plugin fails when trying to open a file with an accent like tèst.pdf, however if I rename it to test.pdf it opens.

The error thrown is:
{status: 9, message: "File not found"}
Is there any solution?

Thanks in advance

@BrunoMinami
Copy link

Since there's no official solution, I'm using a function to remove all "special" characters from filename.
There's also a problem with the file name lenght, that's why it gets only the first 100 characters.

function parseFilename(originalString) {
    var parsed = originalString.substring(0, 100);
    var specialChars = {
        a: /[\xE0-\xE6]/g,
        A: /[\xC0-\xC6]/g,
        e: /[\xE8-\xEB]/g,
        E: /[\xC8-\xCB]/g,
        i: /[\xEC-\xEF]/g,
        I: /[\xCC-\xCF]/g,
        o: /[\xF2-\xF6]/g,
        O: /[\xD2-\xD6]/g,
        u: /[\xF9-\xFC]/g,
        U: /[\xD9-\xDC]/g,
        c: /\xE7/g,
        C: /\xC7/g,
        n: /\xF1/g,
        N: /\xD1/g,
        _: /[^A-Za-z0-9.]/g
    };

    for (var char in specialChars) {
        var regEx = specialChars[char];
        parsed = parsed.replace(regEx, char);
    }

    return parsed;
}

@shnist shnist added the bug label Dec 11, 2018
@shnist
Copy link
Collaborator

shnist commented Feb 12, 2019

@polfdz i believe this was fixed in 2.2.0. Can you confirm the issue is resolved for you in this version?

@ThodorisElissaios
Copy link

ThodorisElissaios commented Apr 20, 2019

the problem still exists ... file with Greek chars throws {status: 9, message: "File not found"}

@shnist shnist changed the title File with accents throws --> file not found Non ASCII characters in filename --> file not found Apr 23, 2019
@shnist
Copy link
Collaborator

shnist commented Apr 23, 2019

yes looks like this issue still exists as all non ASCII characters seem to throw this error. I'm going to close #252 as a duplicate and perhaps pin this issue for now as it seems to be one of the more significant bugs in this plugin.

@shnist shnist pinned this issue Apr 23, 2019
@pwlin
Copy link
Owner

pwlin commented Apr 26, 2019

Can this be an encoding issue with how Java or Objective-C works? Because this plugin does not do anything special.

The way fileName has been constructed must be wrong because the immediate line check for the existence of the file.

private void _open(String fileArg, String contentType, Boolean openWithDefault, CallbackContext callbackContext) throws JSONException {
String fileName = "";
try {
CordovaResourceApi resourceApi = webView.getResourceApi();
Uri fileUri = resourceApi.remapUri(Uri.parse(fileArg));
fileName = fileUri.getPath();
} catch (Exception e) {
fileName = fileArg;
}
File file = new File(fileName);
if (file.exists()) {

If you look back in the git history, you'll see that this has been changed through merging pull requests.

Does Java's File object accept an encoding type?

@Queenhy
Copy link

Queenhy commented May 24, 2019

I have the same problem with german characters ß, ä, ö and ü.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants