Context: I am developing hybrid app with Cordova 6 and SAPUI5 Framework (for now only need to worry about 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.
Input: 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". But FileUploader doesn't provide a fullpath value for the selected item (for security reasons).
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.
Possible solutions:
- Extract the path of the file object by another way.
- Use another input that can provide this path (until now I did not find any).
- Find the path of the file using the filename or maybe the size or something recursively at the phone.
What is the current solution (But really slow):
Write the file with 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.
Thank you by reading. I will upload any new as I have it.