无法在iOS版PhoneGap中获取文件路径

ted

我正在创建一个文件,该文件要通过de.appplant.cordova.plugin.email-composer附加到电子邮件中尽管电子邮件编辑器显示出来,并且包含表明已附加的文件图标,但控制台显示:

2015-06-29 21:21:16.473 bcr[8696:1803] File not found: cdvfile://localhost/persistent/export.csv

以下是我的代码:

//touch event
$(document).ready(function(e) {
    $("#shareBtn").on('touchstart', function (){
       var dummyStore = 'dummyStore';
       stringSuccess(dummyStore);
    });
})

//initiate storing
function stringSuccess(csv){
    DATA2FILE('export.csv',csv,fileSavedSuccess)
}

//open email composer and attach file
function fileSavedSuccess(file){
    console.log(file);
    FILE2EMAIL([],[],[],"QR Scan","Attached CSV file includes results of QR Scan.",file.localURL)
}

//file handling
function DATA2FILE (filename, data, callback) {

    var defaultFileName =  'export-file.txt';

    if (filename === undefined || filename === null) {
        filename = defaultFileName;
    }
    // Request the file system
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

    // Access to filesystem is OK
    function gotFS(fileSystem) {
        fileSystem.root.getFile(filename, {create: true}, gotFileEntry, fail);
    }

    // File is ready
    function gotFileEntry(fileEntry) {
        fileEntry.createWriter(gotFileWriter, fail);
    }

    // Write file content
    function gotFileWriter(writer) {
        writer.onwriteend = function(evt) {
            console.log('finished writing');
            if (callback !== undefined) {
                callback(writer);
            }
        };
        writer.write(data);
    }

    function fail(error) {
        console.log('Error: ', error.code);
    }
}

var FILE2EMAIL =  function (recipient, cc, bcc, subject, body, attachementURL) 
{
    window.plugin.email.open({
        to:recipient, // contains all the email addresses for TO field
        cc:cc, // contains all the email addresses for CC field
        bcc:bcc, // contains all the email addresses for BCC field
        attachments: attachementURL, // contains all full paths to the files you want to attach
        subject:subject, // represents the subject of the email
        body:body, // represents the email body (could be HTML code, in this case set isHtml to true)
        isHtml:true // indicats if the body is HTML or plain text
        });
}

将文件内容打印到控制台时的输出fileSavedSuccess(file)

2015-06-29 22:02:05.781 bcr[8714:60b] {"fileName":"","length":10,"localURL":"cdvfile://localhost/persistent/export.csv","position":10,"readyState":2,"result":null,"error":null,"onwritestart":null,"onprogress":null,"onwrite":null,"onabort":null,"onerror":null}

但是,File Not Found将localURL值传递给FILE2EMAIL时出现错误。路径错了吗?错误在哪里?

ted

我通过使用使其工作fileSystem.root.toURL()通过更改“ fileSavedSuccess”,我能够检索正确的路径并访问文件的内容,如下所示:

function fileSavedSuccess(file){
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
        url = fileSystem.root.toURL()+"export.csv";
        FILE2EMAIL('[email protected],[],[],'QR Scan','See attached file.',url);
                }, function(){
                    alert("fails!");
                });
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从Phonegap IOS中的www获取本地mp3文件的路径?

Cordova / Phonegap-iOS文件系统自定义根路径iosExtraFilesystems无法正常工作

无法获取Uri的文件路径

在iOS中获取资产文件的路径:缺少NSBundle

适用于iOS的fileOpener2 Phonegap / cordova插件中的正确文件路径

在phonegap中,文件阅读器未使用通过FILE_URI获取的路径来读取文件

在Java中获取文件路径

在C中获取文件的路径

无法获取文件的完整路径

CodeIgniter 方法无法正确获取文件路径

(Phonegap + iOS)为什么当我在设备或模拟器中获得文件系统的完整路径时,只能得到“ /”?

无法在Phonegap应用中打开pdf文件

在 Finder 中获取文件的文件路径

无法访问Scala中相对路径中的文件以获取测试资源

在iOS中,使用纯C语言,这是获取本地文件路径的方法吗?

Xamarin.iOS获取用于在电子邮件中附加的图像文件路径

无法在 IntelliJ 中获取资源文件的相对路径 - Java/Selenium

无法从android中的文档获取所选文件的实际视频路径

如何在iOS中获取路径扩展

无法从表中获取正确的图像路径

无法在 SOAP 中获取 XML 元素的路径

无法获取共享文件夹原始文件(系统路径)

从Video Chooser中从Uri获取文件路径

如何从框架中获取文件路径

从Python中的打开文件获取路径

从Codeigniter中的路径获取文件名

获取Java中的文件完整路径

在React Dropzone中获取本地文件路径

快速获取路径 SPM 中的文件