Scenario: My current project involves developing a hybrid app using Cordova 6 and SAPUI5 Framework (mainly focused on Android at the moment).
Objective: I need to quickly copy/move a file to a specific path. This may involve retrieving a FileEntry from a File/Blob object obtained through a FileUploader in sapui5.
Input: FileUploader
Output: File Object To retrieve the selected file, I use the following:
sap.ui.getCore().byId('file-uploader-id').oFileUpload.files[0];
The challenge arises when attempting to copy it to another location: "cordova.file.externalCacheDirectory". The FileUploader doesn't provide a full path for the selected item (due to security reasons).
Attempted Solutions:
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);
});
Outcome:
The proposed solution appears ineffective as the generated path is not accessible (error code 5), rendering it unusable.
Potential Resolutions:
- Determine the file object's path using an alternative method.
- Explore other input options that may provide the required path information.
- Investigate ways to locate the file path by analyzing the filename, size, or similar attributes on the device.
Current Alternative Solution (Though Slow):
Involves writing the file using FileWritter. When utilizing the mentioned code for a video (e.g., 5 seconds long), it takes less than 1 second to copy/move it (possible via camera or video capture using cordova-plugin-media-capture which provides the file path). In comparison, employing the FileWritter method results in a process time of around 10 seconds.
Thank you for reading. Updates to follow as progress continues.