How to access image from native URI (assets-library) in Cordova for iOS

后端 未结 2 1225
無奈伤痛
無奈伤痛 2020-12-31 05:32

I have a Cordova/PhoneGap app which uses the camera to capture a picture. I need to access this picture to send to my server.

For Android I simply use $cordova

相关标签:
2条回答
  • 2020-12-31 06:06

    I was struggling with a similar issue for a while, but I figured it out today. I also thought that the FileSystem APIs didn't work with assets-libary:// URIs -- but that is not the case.

    You should be able to get access to the File object (as well as the actual image name) by using the following code:

    resolveLocalFileSystemURL('assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG', function(fileEntry) {
        fileEntry.file(function(file) {
            var reader = new FileReader();
            reader.onloadend = function(event) {
                console.log(event.target.result.byteLength);
            };
            console.log('Reading file: ' + file.name);
            reader.readAsArrayBuffer(file);
        });
    });
    
    0 讨论(0)
  • 2020-12-31 06:20

    I had success with a simple substitution, like this

    fullPath = fullPath.replace("assets-library://", "cdvfile://localhost/assets-library/")
    

    It works in iOS 9.3

    0 讨论(0)
提交回复
热议问题