简体   繁体   English

在Web中将目录的递归副本复制到Cordova中的设备文件系统

[英]Recursive copy of directory from web to device file system in Cordova

I want copy all files in a web directory on a webserver, and ideally in its component subdirectories, into local device storage for Android and iOS in Cordova using javascript and/or cordova plugins. 我想使用JavaScript和/或cordova插件将Web服务器上Web目录中的所有文件(最好是其子目录中的所有文件)复制到Cordova中的Android和iOS本地设备存储中。

The use case is to copy an entire (smallish) webapp/page from a remote webserver (that we control, and where we posted the content) into local storage on the device. 用例是从远程Web服务器(由我们控制,并在其中发布内容)将整个(较小的)Web应用程序/页面复制到设备上的本地存储中。 This will be used for a form of hot code push for a cordova app. 这将用于cordova应用程序的一种热代码推送形式。

It's possible to copy files using cordova-plugin-file-transfer: 可以使用cordova-plugin-file-transfer复制文件:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/ https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/

or in a more standards-compliant way using XMLHttpRequest (XHR): 或使用XMLHttpRequest(XHR)以更符合标准的方式进行:

https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html

How does one copy an entire directory tree, overwriting an existing one, in device storage. 如何在设备存储中复制整个目录树,并覆盖现有的目录树。

Preferable: method to include error handling for the case that something prevents the full copy from happening, possibly resulting in a partial copy or a corrupted directory. 首选:在某些情况下会阻止错误复制的方法,这种情况会阻止完整复制的发生,从而可能导致部分复制或目录损坏。

Is there an api or combination of apis that do this already? 是否已经有api或api组合已经做到了? If not, does someone have or know of code to accomplish this? 如果不是,是否有人具有或知道执行此操作的代码?

Thanks! 谢谢!

You can look at hydration of phonegap for hot push : 您可以查看phonegap的水合情况以进行热推:

http://docs.phonegap.com/phonegap-build/tools/hydration/ http://docs.phonegap.com/phonegap-build/tools/hydration/

I think it may be suitable for your need. 我认为这可能适合您的需求。

However, be very careful with hot code push because apple doesn't like it very much and it's rather contrary to their guideline. 但是,在进行热代码推送时要非常小心,因为苹果不是很喜欢它,这与他们的准则背道而驰。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM