Save document to a directory within a Cordova Hybrid application

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.

Answer №1

After exploring various options, the solution I found most effective is to modify the input method as follows:

Instead of utilizing the FileUploader, consider using a plugin known as File Selector. This alternative allows for easy access to the FileName, URI, Mime type, and file extension.

This adjustment enables quicker movement or copying of files using the FileEntry.

If any new developments arise related to this topic, I will be sure to update this answer accordingly.

Thank you for your attention.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combine and inject global SCSS file into all components using browserify and vueify

When developing an app, I utilize browserify along with vueify. My goal is to inject a global SCSS file containing variables, mixins, colors, etc., into Vue so that it is accessible to all components without the need for explicit import statements in each ...

Can Self-Invoking Functions, Resharper 6.1, and JS Lint all Play Nice Together?

Consider this piece of JavaScript code: MyCompany.MyProduct = {}; (function () { "use strict"; MyCompany.MyProduct.doSomethingAmazing = function () { }; }()); This approach is acceptable and passes Mr Crockford's JavaScript lint. Howe ...

Verify if the link includes https:// while using angularjs

In my angular app, there is a lot of data stored in JSON format. [ {"link": "https://stackoverflow.com"}, {"link": "https://stackoverflow.com"}, {"link": "id-aW783D"}, //This data is incorrect {"link": "https://stackoverflow.com"} ] However, the ...

Loading the JS file after waiting on Lib (IronRouter) causes the HTML not to load properly

Currently, I am utilizing wait-on-lib along with IRLibLoader.load() in conjunction with Iron-Router, following the instructions provided in the tutorial found at: . My objective is to load external javascript code. Below is a snippet of my routing code: R ...

How to target a single TypeScript file in a React project that does not use TypeScript for compilation

I created a ReactJS application using the following command: $ npx create-react-app react-app-vanilla This app includes the following files: /.gitignore /README.md /package.json /public/favicon.ico /public/index.html /public/logo192.png /public/logo512.pn ...

Issues with the directory for Chrome

Currently, I am utilizing jQuery and running an HTML file on my local machine without a server. Interestingly, the code works perfectly fine on Firefox but encounters issues on Chrome: $('#result').load('test.html'); It appears that t ...

Creating a jQuery thousands separator without losing the decimal accuracy with .toFixed(2)

I'm currently working on a Wordpress project where I need to create a pricing table using jQuery. One of the specific requirements is to format the numbers in thousands with spaces, like converting 1000 to 1 000. Although I have attempted various jQu ...

Tips on aligning a span element at the center of an image without losing its mouseover

<div class="pic"> <img src="image.jpg" height="250"/> <span class="text" style="display:none">text here</span> </div> <scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </scrip ...

How can I sort by the complete timestamp when using the Antd table for dates?

I have an item in my possession. const data: Item[] = [ { key: 1, name: 'John Brown', date: moment('10-10-2019').format('L'), address: 'New York No. 1 Lake Park', }, { ...

Capturing jQuery ajax requests in Angular

Within my Angular application, I am utilizing the integrated $.couch API from CouchDB. My goal is to intercept every ajax request, regardless of whether it originates from Angular's $http service or jQuery's $.ajax (which is utilized by $.couch). ...

incorporating new content into a jQuery list widget

i am currently exploring this demo for niceforms: http://www.emblematiq.com/lab/niceforms/demo/v20/niceforms.html i want to understand how i can integrate a datasource with the existing list on this page: <select size="4" name="languages[]" id="langu ...

Discovering the current time and start time of today in EST can be achieved by utilizing Moment.js

Need help with creating Start and End Time stamps using Moment.js in EST: Start Time should reflect the beginning of today End Time should show the current time. This is how I have implemented it using moment.js: var time = new Date(); var startTime=D ...

What is the method for retrieving a temporary collection in a callback function when using node-mongodb-native find()?

Is it possible to retrieve a temporary collection from a find() operation instead of just a cursor in node-mongodb-native? I need to perform a mapReduce function on the results of the find() query, like this: client.open(function(err) { client.collect ...

Ways to delete an item from the environment

I need to change the position of some cylinders in the scene by removing them and adding new ones. Here is a snippet of code to show how I currently place the cylinders: for (i = 0; i < cylinderCount; i++) { var geometry = new THREE.CylinderGeometry ...

The textbox fails to update when the condition in the IF statement is met

In the following code, I have an input box with the ID volumetric_weight that gets updated on keyup. However, the second textbox with the ID volumetric_price does not update as expected, even though I believe I wrote it correctly. I am wondering if there ...

I have encountered an issue with my rows breaking improperly when viewing them in a PDF format, particularly when I include a minus

Whenever I try to view my HTML page in PDF form, I encounter an issue. The problem arises when the numerical values are too large, causing a line break between the minus sign and the values. Here is an example of the HTML page which appears perfectly: ent ...

Utilizing AJAX and PHP to Showcase Data

Instructions for program flow: 1. When the page loads, the chart will display the total sales from all branches. 2. Upon selecting a specific branch from the dropdown menu, the chart should show the total sales for that particular branch. I am encounterin ...

Adjusting line sizes in textView on Android Studio: A comprehensive guide

Is there a way to set the line height size for each row in a textview while also setting the text size to 18sp? I know we can use android:maxLines="" to split the textview into multiple rows, but I would like to specify the line height size as well (not ...

Using Special Characters in React JS Applications

When handling CSV uploads with accented characters such as émily or ástha, I encountered the need to encode and pass them to the backend. Experimenting with different approaches, I tried adjusting the file type in FormData from 'text/plain' to ...

Troubleshooting: Issues with Custom Image Loader in Next.js Export

I'm encountering a problem while attempting to build and export my Next.JS project. The issue lies with Image Optimization error during the export process. To address this, I have developed a custom loader by creating a file /services/imageLoader.js ...