Locally Stored Image is not displaying in IOS Cordova

306 Views Asked by At

I have a cordova hybrid app that has to display image from local file. But its not displaying the images.

Using filetransfer plugin images are getting downloaded in local document folder with help of phonegap.

Source Code for Image Download using PhoneGap

DirectoryEntry directoryEntry;
String rootDir;
String localfilepath;
String uri = servlet get the uri 

FileTransfer fileTransfer = phoneGap.getFile().createFileTransfer();

phoneGap.getFile().requestFileSystem(FileSystem.LocalFileSystem_PERSISTENT, 5 * 1024 * 1024, new FileCallback<FileSystem, FileError>() {

    @Override
    public void onSuccess(final FileSystem fileSystem) {
        rootDir = entry.getRoot().toURL();
        final Flags create = new Flags(true, false);
        // creating folder SampleFile
        fileSystem.getRoot().getDirectory("SampleFile", create, new FileCallback<DirectoryEntry, FileError>() {

        @Override
        public void onSuccess(DirectoryEntry entry) {

        directoryEntry = entry;

        entry.getFile("welcome.jpg", create, new FileCallback<FileEntry, FileError>() {
                                            
        @Override
        public void onSuccess(final FileEntry entry1) {
                        
        //file created
                                        
                        }
                }
        }
    }
}

    fileTransfer.download(uri, directoryEntry.toURL()+"/"+"welcome.jpg", new 
    FileDownloadCallback() {

    @Override
    public void onSuccess(FileEntry result) {
    localfilepath = rootDir+result.getFullPath()    //This  my local file path

    }

  }

//Finally setting the local file path in image field

Image contentImage = new Image();
contentImage.setSize("200px", "200px");
contentImage.setUrl(localfilepath);

Above code is not displaying the image . For android its working fine but for ios iam facing problem.This my local file path

file:///var/mobile/Containers/Data/Application/9DAC70D-36AD-42BE-930C-644514B/Documents/SampleFile/welcome.jpg

Bascially UI developed in GWT(Google Web Tool Kit). For accessing FileSystem iam using PhoneGap For Build IOS App iam using Cordova

I tried lot but still is not working. Any help would be greatly appreciated. Thanks .

0

There are 0 best solutions below