gpt4 book ai didi

javascript - 使用带有 Meteor 的 Cordova 文件插件,收到代码 : 5 ENCODING_ERROR in getDirectory() callback

转载 作者:行者123 更新时间:2023-11-28 07:12:41 25 4
gpt4 key购买 nike

我在 iOS 上使用 Cordova v4.2.0 和 Meteor v1.1.0.2。我使用 FileTransfer 插件 (v0.4.3) 下载内容(图像、音频等),使用文件插件 (v1.3.3) 导航文件系统。

当用户下载插件并首次打开应用程序时,会下载内容。这有效。但是,有时用户需要选择一批新的内容来下载,在这种情况下我必须再次调用此函数来下载更多内容。第二次,当我使用 filesystem.root.getDirectory() 检索内容目录时,我总是收到 ENCODING_ERROR。

deferred = Q.defer()
numToLoad = urls.length
numRecieved = 0
urlsToTryAgain = []

onError = (url)->
return (err)->
console.log "Error finding file system: "
console.log err
deferred.reject(err)

onFileEntrySuccess = (url)->
return (fileEntry)->
ft = new FileTransfer()
endpnt = url.endpointPath()
uri = encodeURI(endpnt)
targetPath = fileEntry.toURL()

ft.onprogress = (event)->
total = Session.get "total bytes"
if !total
total = event.total
Session.set "total bytes", total
bytesLoaded = event.loaded
Session.set "bytes downloaded", bytesLoaded

onTransferSuccess = (entry)->
numReceived++
if numReceived == numToLoad
deferred.resolve(entry)

onTransferError = (error)->

#TIMEOUT_ERROR
if error.code == 3
#try to download the file again
ft.download(uri, targetPath, onTransferSuccess, onTransferError)
else
deferred.reject(error)

#download the file from the endpoint and save to target path on mobile device
ft.download(uri, targetPath, onTransferSuccess, onTransferError)


onDirEntrySuccess = (url, directories)->
return (dirEntry)->
if directories.length == 0
file = url.file()
dirEntry.getFile file, {create: true, exclusive: false}, onFileEntrySuccess(url), onError(file)
else
#A branch of the directory tree looks like Content/Image/img.png
dir = directories[0] + '/'
remainingDirs = directories.splice(1)
dirEntry.getDirectory dir, {create: true, exclusive: false}, onDirEntrySuccess(url, remainingDirs), onError(dir)


window.requestFileSystem LocalFileSystem.PERSISTENT, 5*1024*1024, (fs)->
for url in urls
#returns an array of the directories, eg ['Content', 'Image']
directories = url.directories()
#TODO: this should be done in the object
firstDir = directories[0] + '/'
remainingDirs = directories.splice(1)
#retrieve each directory in the tree one by one, creating it if necessary
fs.root.getDirectory firstDir, {create: true, exclusive: false}, onDirEntrySuccess(url, remainingDirs), onError(url)
, (err)->
console.log "ERROR requesting local filesystem: "
console.log err
promise.reject err

return deferred.promise

现在,在下载新批处理之前,我会删除手机中的所有本地内容,确保下一批的目录是干净的。但是,这并没有解决错误。

如有任何帮助,我们将不胜感激。即使了解可能导致 ENCODING_ERROR 的原因也会有所帮助。

(在使用 getDirectory 一次一个目录向下移动树之前,我尝试简单地使用 fs.root.getFile 和文件目标的完整路径(例如“/Content/Image/img.png”) 。但是,这总是以 ABORT_ERROR 结束。这种迭代逐步解决方案解决了该问题。)

最佳答案

我发布这个问题的时候就解决了:p。

我正在启动本地服务器来提供我下载的文件(因为meteor无法访问meteor.local之外的文件)。不知何故,本地主机 url 被附加到第二波中每个 url 的目录数组中,因此不是 ['Content', 'Image'] 而是 ['http','127.0.0.1:8080', 'Content' , '图像']。自然,这导致了 ENCODING_ERROR。

关于javascript - 使用带有 Meteor 的 Cordova 文件插件,收到代码 : 5 ENCODING_ERROR in getDirectory() callback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31147548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com