简体   繁体   中英

how to convert a file url to data uri in javascript

I want to convert a file url to data uri. please help on this. Im trying a phonegap app in which i am taking pic from camera and upload. but when i'm using datauri it crashes due to memory leak issue. so i'm trying to do in file url way.

your app crash is not because of DATA_URL, it is because your image is too big to upload. try my code for your problem. You need to set quality below 50 and make sure reduce width and height. Use FILE_URI instead DATA_URL .

function capturePhoto() {
        // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
            quality: 30,
        targetWidth: 600,
        targetHeight: 600,
        destinationType: navigator.camera.DestinationType.FILE_URI,
        saveToPhotoAlbum: true,
        correctOrientation: true
    });
}

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