简体   繁体   English

使用cordove captureimage到设备文件名时,媒体文件中的本地图像文件路径不同

[英]Local image filepath different in mediafile when using cordove captureimage to device file name

I have had this issue start to appear with the device file name being created in this format:我已经开始出现这个问题,以这种格式创建的设备文件名:

.../DCIM/Camera/IMG_20170819_155509.jpg

But the media file data when using Cordova captureImage being returned as:但是使用 Cordova captureImage 时的媒体文件数据被返回为:

.../DCIM/Camera/1503140105277.jpg

Therefore being unable to return the image.因此无法返回图像。

Here is the code:这是代码:

$('body').off('click', '#add-image-inspect-attr-list').on('click', '#add-image-inspect-attr-list', function(event) {                
            var options = { limit: 1 };
            navigator.device.capture.captureImage(inspectAttrPictureSuccess, inspectPictureError, options);
            $(this).off();
        });

function inspectAttrPictureSuccess(imageData) {

console.log(imageData);
var countOfImg = $('.image-display-inspect-attr-list').children().length;
var file = {
    ContentType: "image/jpeg",
    base64: imageData,
    Data: imageData,
    ID: countOfImg
};

var fileName = file.base64;
inspectShowAttrFile(fileName,0);
}

function inspectShowAttrFile(fileName, type) {

var countOfImg = $('.image-display-inspect-list').children().length;
$('.image-display-inspect-list').append('<img id="inspect-img-index-' + countOfImg + '" class="img-responsive img-thumbnail img-inspect" src="' + fileName[0].fullPath + '">');
}

The app is built with cordova 6.3.1 and the device has andriod 4.4.2该应用程序使用cordova 6.3.1构建,设备具有andriod 4.4.2

This works on some devices but not others这适用于某些设备,但不适用于其他设备

To get around this issue, I had to check what the last file added was to the image file location.为了解决这个问题,我必须检查最后添加到图像文件位置的文件。 Get the folder path, get the latest file added, then update the image data created by the captureImage function with the new file name and location data:获取文件夹路径,获取最新添加的文件,然后使用新的文件名和位置数据更新由 captureImage 函数创建的图像数据:

function inspectAttrPictureSuccess(imageData) {


var deviceImageFolder = imageData[0].localURL.replace(imageData[0].name, '');

window.resolveLocalFileSystemURL(deviceImageFolder, function (dirEntry) {
    var directoryReader = dirEntry.createReader();
    directoryReader.readEntries(successfile, failfile);
}, function (err) {
    var errToSave = err.message;
});

function successfile(entries) {
    var latestimage = entries[entries.length - 1];

    imageData[0].fullPath = latestimage.fullPath
    imageData[0].localURL = latestimage.nativeURL
    imageData[0].name = latestimage.name

    var countOfImg = $('.image-display-inspect-attr-list').children().length;
    var file = {
        Filename: "inspect-attr-img-" + Math.random().toString(36).substring(2, 15) + ".jpg",
        ContentType: "image/jpeg",
        base64: imageData,
        Data: imageData,
        ID: countOfImg
    };

    inspectImageAttrFileSendAry.push(file);
    inspectImageFileSendALLAry.push(file);
    console.log(inspectImageAttrFileSendAry);
    console.log(inspectImageFileSendALLAry);
    var fileName = file.base64;
    inspectShowAttrFile(fileName, 0);

}
function failfile(error) {
    console.log("Failed to list directory contents: ", error);
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当图像名称存储在本地存储中时,在 reactjs 中显示图像 - Display image in reactjs when the image name is stored in local storage 如何将MediaFile对象转换为File对象? - How to convert MediaFile Object to File Object? 如何从内容字符串获取文件路径和文件名? - How to get a filepath and file name from a string of contents? 使用本地 <image file> 用于微软定制视觉 - Using local <image file> for microsoft custom vision 选择设备时更改图像并在选择不同设备后将其返回 - Change image when selecting device and return it back after selecting different device 画布DataURL以使用filePath进行映像 - Canvas DataURL to image with filePath 使用 addEventListener 单击图像时如何显示图像的文件名? - How would I show the file name of an image when clicking on it using addEventListener? 使用IE 6更改本地文件时刷新本地HTML - Refresh a local HTML when a local file has changed using IE 6 如何使用Objective-C从IOS Cordova中的设备(本地DB)删除图像 - How to delete a image from Device (Local DB) in IOS Cordova using Objective-C 无法使用angularjs ng-src访问设备本地存储中的图像文件 - Cannot access image files inside my device local storage using angularjs ng-src
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM