I have an application using cordova 3.4 and file 1.1.0. If I copy an image using the camera module, I use
myFileObj.path = file.toNativeURL()
to get the file path. If I put this path in the img tag, I will be shown an image on Android. On iOS, this does not work. Result of file.toNativeURL ():
myFileObj.path -> file:///Users/.../Library/Application%20Support/..../myFolder/myImage.JPG
Using file 1.0, I had to create a url and it looked like this:
myFileObj.path = dirTarget.toURL() + '/' + targetFileName
myFileObj.path -> cdvfile://localhost/persisten/myFolder/myImage.JPG
If the video and audio did not work, but at least the photos.
Using the file 1.1.0 / 1.1.1, the result of this method is also different:
myFileObj.path -> file:
This also does not work on iOS.
How can I get a working file path using the cordova file module versions 1.1.0 and 1.1.1?
EDIT: what am I doing and what is not working:
, .
Android iOS:
Android src media-tags , iOS src.
-:
navigator.camera.getPicture(onSuccess, onFail, {
destinationType: Camera.DestinationType.NATIVE_URI,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
mediaType: Camera.MediaType.ALLMEDIA
});
:
function onSuccess(imageData) {
A.StoreFile(imageData, id);
}
:
A.StoreFile = function(file, idBox) {
var targetDirectory = Config.getRootPath();
window.resolveLocalFileSystemURL(file, resolveFileSystemSuccess, resolveFileSystemError);
function resolveFileSystemSuccess(fileEntry) {
fileEntry.file(function(filee) {
mimeType = filee.type;
getFileSuccess(fileEntry, mimeType);
}, function() {
});
}
function getFileSuccess(fileEntry, mimeType) {
var targetFileName = name + '.' + fileNativeType;
var parentName = targetDirectory.substring(targetDirectory.lastIndexOf('/')+1),
parentEntry = new DirectoryEntry(parentName, targetDirectory);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory(targetDirectory, {create: true, exclusive: false}, function(dirTarget) {
fileEntry.copyTo(dirTarget, targetFileName, function(entry) {
addFileToLocalStorage(entry);
}, function() {
})
})
}, resolveFileSystemError);
}
- localStorageObject
function addFileToLocalStorage(file) {
fileList.addFile(
{
name:file.name,
internalURL: file.toNativeURL()
});
}
dom:
myElement.find('.myMimeTypeTag').attr('src', fileList[f].internalURL);
android, iOS.
iOS- img-:

:
DEPRECATED: Update your code to use 'toURL'
toURL
id="org.apache.cordova.file"
version="1.1.1-dev"