[英]Copy file to a path with Cordova Hybrid app
Context : I am developing hybrid app with Cordova 6 and SAPUI5 Framework (for now only need to worry about Android). 上下文 :我正在使用Cordova 6和SAPUI5 Framework开发混合应用程序(现在只需要担心Android)。
What I want : Copy/move a file to a path fast. 我想要的 :快速将文件复制/移动到路径。 Maybe getting a FileEntry from a File/Blob object from a FileUploader on sapui5.
也许从sapui5上的FileUploader从File / Blob对象获取FileEntry 。
Input : FileUploader 输入 : FileUploader
Output : File Object So I get the file when I select it by doing the following: 输出 :文件对象所以当我选择它时,我通过执行以下操作获取文件:
sap.ui.getCore().byId('file-uploader-id').oFileUpload.files[0];
So then I have to copy it to another location: " cordova.file .externalCacheDirectory". 所以我必须将它复制到另一个位置:“ cordova.file .externalCacheDirectory”。 But FileUploader doesn't provide a fullpath value for the selected item ( for security reasons ).
但FileUploader不为所选项提供完整路径值( 出于安全原因 )。
What I tried : 我尝试了什么 :
var sPath = URL.createObjectURL(oFile);
var pCopyFrom = new Promise((resolve, reject) => {
window.resolveLocalFileSystemURL(sPath, resolve, reject);
});
var pCopyTo = new Promise((resolve, reject) => {
var sExternalCachePath = cordova.file.externalCacheDirectory;
window.resolveLocalFileSystemURL(sMediaPath, resolve, reject);
});
Promise.all([pCopyFrom, pCopyTo]).then(aValues => {
aValues[0].moveTo(aValues[1], aValues[0].name, cbSuccess, cbError);
});
Result : 结果 :
Solution seems to don't work because the generated path is not available (error code 5), this path is not valid for use it like this. 解决方案似乎不起作用,因为生成的路径不可用(错误代码5),此路径无效,因此使用它。
Possible solutions : 可能的方法 :
What is the current solution (But really slow) : 目前的解决方案是什么(但确实很慢) :
Write the file with FileWritter . 使用FileWritter编写文件。 If I have the path and I use the above code to a video (of 5 seconds of duration) it spends less than 1 second (thanks to FileEntry ) to copy/move it (using a camera capture or video capture with cordova-plugin-media-capture that gives the path of the file), while using FileWritter method it spends like 10 seconds to write it.
如果我有路径并且我将上述代码用于视频(持续时间为5秒),则花费不到1秒 (感谢FileEntry )来复制/移动它(使用摄像头捕获或使用cordova插件进行视频捕获-媒体捕获 ,提供文件的路径),而使用FileWritter方法花费10秒钟来编写它。
Thank you by reading. 谢谢你阅读。 I will upload any new as I have it.
我会上传任何新的,因为我有它。
The final solution is the second option that I said on the question, changing the input method: 最后的解决方案是我在问题上说的第二个选项,改变了输入法:
Instead of using the FileUploader as input, use a plugin called File Selector . 不使用FileUploader作为输入,而是使用名为File Selector的插件。
You can get the FileName, URI , Mime type and the file extension 您可以获取FileName, URI ,Mime类型和文件扩展名
So now I can move/copy the file faster with the FileEntry . 所以现在我可以使用FileEntry更快地移动/复制文件。
Anyway I will update this answer if I find something relevant to this theme. 无论如何,如果我找到与此主题相关的内容,我会更新此答案。
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.