【问题标题】:PhoneGap File API issue while saving image captured on a directory保存在目录中捕获的图像时出现 PhoneGap File API 问题
【发布时间】:2014-02-17 02:16:11
【问题描述】:

我有以下代码将图像存储在 S4 上的目录“myApp”中

function gotFileEntry(fileEntry){   
var gotFileSystem = function(fileSystem) {
    alert("got file Sys: " + fileSystem.name);

    fileSystem.root.getDirectory("myApp", {
        create : true
    }, function(dataDir) {
        alert("got dir :" + dataDir.fullPath);
        alert("got image file entry: " + fileEntry.fullPath);
        // move the file
        fileEntry.moveTo(dataDir, "1.jpg", null, failFS);

    }, failFS);

};

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem,failFS);
}

function SaveImage(){
   // curImageURI has value of imageURI  from onPhotoURISuccess()
   window.resolveLocalFileSystemURI(curImageURI, gotFileEntry, failFS);
}

“myApp”目录在 S4 上的路径:/storage/emulated/0/myApp

curImageURI 中的值:/storage/emulated/0/Android/data/com.apps.myApp/cache/1392602140698.jpg

以下是我收到的警报:
得到文件 Sys: 持久
得到目录://myApp
得到图片文件入口:/1392602140698.jpg

在 fileEntry.moveTo(...) 时出现以下错误。

System.err java.io.FileNotFoundException: 源不存在

我不明白我哪里出错了。如果有人可以帮助我,我将不胜感激。 提前谢谢你。

【问题讨论】:

  • 您认为我的答案正确吗,请检查为正确答案。

标签: android image cordova fileapi


【解决方案1】:

您的代码是正确的。这是一个与 phonegap 3.3.0 相关的错误。请参考发行说明:

Phonegap (Cordova) 3.4.0 Release notes

  1. 升级你的phonegap版本。

    MAC/Linux: $ npm update -g phonegap

    Windows: C:> npm update -g phonegap

  2. 从头开始创建项目并测试您的代码,它应该可以工作。

    phonegap 创建测试

  3. 进入创建的目录:

    cd 测试

  4. 为安卓构建:

    phonegap 构建安卓

  5. 复制/粘贴您的代码并进行测试。

希望对您有所帮助!

【讨论】:

    【解决方案2】:

    我遇到了一个非常相似的问题。

    在我的相机 api 调用中,我使用 targetWidth: ,targetHeight: 调整图像大小 我一直在获取源不存在错误。

    我删除了宽度和高度,它可以正常工作。

    【讨论】:

    • 克里斯,你能分享你的工作代码吗?以及你成功的phonegap版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多