简体   繁体   中英

Cordova Camera Plugin Android appends extra information to the end of FILE_URI

I'm using the Cordova Camera Plugin in an Ionic application. Everything works as expected on iOS. On Android, when the sourceType is set to CAMERA and destinationType is set to FILE_URI , it works as expected, returning a path like this: file:///storage/emulated/0/Android/data/com.myappname.myapp/cache/imageName.jpg

However, when the sourceType is set to PHOTOLIBRARY or SAVEDPHOTOALBUM and the destination type is set to FILE_URI , it returns a path with extra information (namely a query string) at the end of the file, making it impossible to load and use that file (ie. with CordovaFileTransfer). The path it returns is like this: file:///storage/emulated/0/Android/data/com.myappname.myapp/cache/image.jpg?12764830288374

The issue is the query string ?12764830288374 on the end. I understand this is done for caching issues in browsers, but why does Cordova Camera return the FILE_URI this way and what can be done to change it?

I realize I could simply strip off everything on the path after the question mark but that seems like a hacky solution. I'd like to know why it is returning the path this way and how to fix it properly.

Note: I have also tried returning it as a NATIVE_URI and the same issues holds true - it appends a question mark with a list of numbers to the end of the file path that prevents cordovaFileTransfer from properly uploading the file.

I don't know why it appears in this specific instance, but;

Adding a random number to the end like that prevents the browser cache from using an old version of the file. This is very useful because if you were to take a new picture, and tried to display that, you would most likely see the old picture.

This is essentially a "hack" around the browser cache. Somehow the system under the hood is doing you a favour. Since the number is different each time the url is different, even though the file is the same one. Browsers only cache URLs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM