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
Invalid status(404 OK) on file requests on Android #380
Comments
Can you provide a sample app? I can't reproduce. |
I have the same problem.
This resolves to
If I load it in an image, I get a 404 (OK) |
It seems it can't read from cordova.file.applicationDirectory, Anywhere else it works as expected |
I have the same issue on android as well: let path = cordova.file.applicationDirectory + "www/" + relativePath;
path = window.Ionic.WebView.convertFileSrc(path);
fetch(path) getting error 404. |
I fought hours with exactly the same issue to finally figure out that paths are case sensitives for the Webview in Android ! Hope it will help ! |
You don't really need to use But this looks like a different problem from the OP, so can any of you having problems with |
Thanks. I eventually solved it like you mentioned. In addition to this, I was forced to also pass the file extension so that it can detect the myme-type. Hope this will help someone |
I have created a new issue as was requested by @jcesarmobile: #397 |
@HarelM Why don't you abstract the code in a plugin (I'm doing this), or a service within the app? |
@alexandruluca I did, just wanted to make sure this is a know issue here so it can be tracked and fixed :-) |
Same problem here. |
still not fixed? |
|
I was facing a very similar issue with Cordova Media Plugin File Path Compatibility with Android API 33 Problem:When updating the target and compile version of the app from API 31 to API 33, issues arose with the Cordova Media Plugin. The problem seems to stem from the way file paths are handled in API 33, specifically with the Root Cause:The Original Implementation in public static String stripFileProtocol(String uriString) {
if (uriString.startsWith("file://")) {
return Uri.parse(uriString).getPath();
}
return uriString;
} Proposed Fix:To address this, I extended the stripFileProtocol method to handle both the file:// and http://localhost/ prefixes: public static String stripFileProtocol(String uriString) {
if (uriString.startsWith("file://")) {
return Uri.parse(uriString).getPath();
} else if (uriString.startsWith("http://localhost/")) {
uriString = uriString.replace("http://localhost/", "");
return Uri.parse(uriString).getPath();
}
return uriString;
} By adding a check for http://localhost/ and subsequently stripping it, we ensure that the path is correctly formatted for file operations on API 33 and above. Recommendation:It's advisable for the Cordova Media Plugin maintainers to consider this change or a similar approach to ensure compatibility with Android API 33 and future versions. I hope this solution aids others facing similar challenges with the Cordova Media Plugin on newer Android API versions. Ensuring seamless path handling is essential for the continued robustness of the plugin. plus this problem was an annoying pain to figure out what was even happening |
I have a problem, when getting file content an Android. Plugin handles request and return response with incorrect status value (404 OK), when everything is OK. It's because
available()
method on inputStream returns 0example path is
/_app_content_/com.android.contacts/contacts/1/photo
, it is got from cordova-contacts-pluginThe text was updated successfully, but these errors were encountered: