2

我正在开发一个 iPhone 应用程序,用户可以在其中使用 Xcode 中的 PhoneGap 和 HTML 下载文件(.pdf、.docx 等),然后“在线”查看它们(本质上,用户查看从网站下载的文件))或“离线”(用户已预先下载它们,现在正在硬编码正在下载的文件,并且可以从设备上的 LocalFileSystem 查看文件)。我可以很好地下载一个 .txt 文件;

    function downloadEditFile() {
        var fileDownloadEdit = new FileTransfer();
        var uri = encodeURI("http://dl.dropbox.com/u/97184921/editme.txt");

        fileDownloadEdit.download(
                uri,
                pathToRoot + '/editme.txt',
                function(entry) {
                    console.log("download complete: " + entry.fullPath);
                    alert("File Downloaded. Click 'Read Editable Downloaded File' to see text");
                },
                function(error) {
                    console.log("download error source " + error.source);
                    console.log("download error target " + error.target);
                    console.log("upload error code" + error.code);
                }
        );
    }

但是当我尝试开发它以下载 .pdf 文件时,它会中断。我需要帮助,我哪里出错了?我真正要做的就是将文件名更改为Holidays.pdf,但console出现了说;

2013-03-14 11:06:47.921 TestApp1[265:15b03] -[CDVFileTransfer download:] [Line 313] File Transfer downloading file...
2013-03-14 11:06:48.553 TestApp1[265:15b03] File Transfer Finished with response code 404
2013-03-14 11:06:48.553 TestApp1[265:15b03] -[CDVFileTransferDelegate connectionDidFinishLoading:] [Line 437] Write file /Users/administrator/Library/Application Support/iPhone Simulator/6.1/Applications/AF96D141-0CE5-4D60-9FA8-8A8F9A999C81/Documents/Holidays.pdf
2013-03-14 11:06:48.554 TestApp1[265:15b03] FileTransferError {
code = 3;
"http_status" = 404;
source = "http://dl.dropbox.com/u/97184921/Internship%2520Stuff/Holidays.pdf";
target = "/Users/administrator/Library/Application Support/iPhone Simulator/6.1/Applications/AF96D141-0CE5-4D60-9FA8-8A8F9A999C81/Documents/Holidays.pdf";
}
2013-03-14 11:06:48.556 TestApp1[265:15b03] [LOG] download error source http://dl.dropbox.com/u/97184921/Internship%2520Stuff/Holidays.pdf
2013-03-14 11:06:48.556 TestApp1[265:15b03] [LOG] download error target /Users/administrator/Library/Application Support/iPhone Simulator/6.1/Applications/AF96D141-0CE5-4D60-9FA8-8A8F9A999C81/Documents/Holidays.pdf
2013-03-14 11:06:48.557 TestApp1[265:15b03] [LOG] upload error code3

怎么了?我对 Xcode 和 PhoneGap 还很陌生,所以任何帮助都会很棒:)

这是用于下载 pdf 文件的确切 JavaScript;

    function downloadPDFFile() {
        var fileDownloadPDF = new FileTransfer();
        var uri = encodeURI("http://dl.dropbox.com/u/97184921/Internship%20Stuff/Holidays.pdf");

        fileDownloadPDF.download(
                                  uri,
                                  pathToRoot + '/Holidays.pdf',
                                  function(entry) {
                                  console.log("download complete: " + entry.fullPath);
                                  alert("File Downloaded. Click 'Read Editable Downloaded File' to see text");
                                  },
                                  function(error) {
                                  console.log("download error source " + error.source);
                                  console.log("download error target " + error.target);
                                  console.log("upload error code" + error.code);
                                  }
                                  );
    }

我用来调用该函数的 HTML 是;

<button onclick="downloadPDFFile();">Download PDF File</button> <br>
4

1 回答 1

1

看起来你的网址是错误的。我认为 JS 从字面上翻译 % 在您的 URI 字符串中。(JS的第3行)

如果您查看控制台输出中的 URL,它是“Internship%2520...”而不是“Internship%20”。很确定这就是为什么您在文件上得到 404,这显然意味着它无法下载。

重命名您的 DB 文件夹,使其中没有空格...使用下划线或只使用一个单词。

于 2013-03-18T10:45:03.113 回答