Phonegap 3.0 FileTransfer下载不工作 [英] Phonegap 3.0 FileTransfer download not working
问题描述
我是这样下载一个多部分mime编码的图像到iOS:
I'm downloading a multi-part mime encoded image to iOS like this:
var ft = new FileTransfer();
url = encodeURI(url);
ft.download(url, path, function(fileEntry) {}, function(err) {});
path = "file://localhost/var/mobile/Applications/D702F059-A29F-4FF4-A165-D4A903DEDE7D/Documents/captured/2419747919.jpeg"
并得到以下错误:
body: "Could not create path to save downloaded file: The operation couldn’t be completed. (Cocoa error 513.)"
code: 1 (file not found)
http status: 200
这暗示一个无效的路径,但我看不到任何错误。我得到这样的路径:
This hints to an invalid path, but I can't see anything wrong with it. I get the path like this:
path = fs.root.toURL();
其他一切正常,文件可以存储在完全相同的路径通过拍照。只是不通过FileTransfer下载。
Everything else works fine and files can be stored in exactly the same path by taking photos. Just not via a FileTransfer download.
Phonegap 3.0中的任何想法或错误?感谢!
Any ideas or a bug in Phonegap 3.0? Thanks!
UPDATE - 解决方法
FileWriter可以运行, iOS和Android。示例代码:
FileWriter works and now even saves blobs on iOS and Android. Example code:
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
var blob = new Blob([xhr.response], {type: 'image/jpeg'});
// save via FileWriter
};
xhr.send();
推荐答案
我在iOS中发现了问题:
I found the problem in iOS:
路径:
path =file://localhost/var/mobile/Applications/D702F059-A29F-4FF4-A165-D4A903DEDE7D/Documents/captured/2419747919.jpeg
The path: path = "file://localhost/var/mobile/Applications/D702F059-A29F-4FF4-A165-D4A903DEDE7D/Documents/captured/2419747919.jpeg"
无法使用,因为它是一个包含localhost的网址。
does not work because it is an URL with "localhost" in it.
从Cordova中的FileEntry,可以使用fullPath和toURL...在Android上,他们都可以写一个文件。
在iOS上只有fullPath工作... URL不能成功写入文件!
From FileEntry in Cordova one can get a string using "fullPath" and "toURL" ... on Android they work both to write a file. On iOS only the fullPath works ... the URL does not successfully write a file!
这篇关于Phonegap 3.0 FileTransfer下载不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!