Uncaught Reference Error: LocalFileSystem not defined - javascript

This question has been asked before on this forum but I could not find a satisfactory solution to the problem. Hence the question again.
I am trying to download and store a file from the internet into the local file system on my phone. I am getting the following error:
Uncaught ReferenceError: LocalFileSystem is not defined
The code I have so far is:
function storeFile(bucketName, csvfile){
var region;
s3Client.getBucketLocation(params = {Bucket: bucketName},function(err,data){
if(err) console.log("Error :: Cannot retrieve bucket location", err);
else {
console.log(data);
region = data;
}
});
var url = "http://s3-"+region+".amazonaws.com/"+bucketName+"/"+csvfile;
window.requestFileSystem(LocalFileSystem.PERSISTENT,0,
function(fs){
filePath = fs.root.fullPath + "/" + csvfile;
fileTransfer = new FileTransfer();
fileTransfer.download(url, filePath,
function (entry) {
console.log(entry.fullPath); // entry is fileEntry object
},
function (error) {
console.log("Some error");
});
}, function(err){
console.log("Request File System failure");
});
}
Do I need to add any plugins into my app? I already have the File and FileTransfer plugins added. By the way this function is called after onDeviceReady is fired.
EDITED:
I am not working with AngularJs. My code is on NodeJs. Secondly, I have no dependencies like the ionic framework etc. which could possibly present a problem. This same code has been tested on other data which have been successfully downloaded and stored. The problem has occurred after I changed the code to download from a specific location on the amazon server. If someone could address this problem for me, it would be great. I am able to access the bucket and the region through code. The only problem is the LocalFileSystem.

Was able to solve the problem. Just removed and re-added the file and file-transfer plugins.
cordova plugin rm org.apache.cordova.file and cordova plugin rm org.apache.cordova.file-transfer to remove.
cordova plugin add org.apache.cordova.file and cordova plugin add org.apache.cordova.file-transfer to add.
It may tell you that these plugins are soon to be deprecated or something like that. You also have the option of using the later versions. To add you can use
cordova plugin add cordova-plugin-file and cordova plugin add cordova-plugin-file-transfer. Just check if they are available under the respective builds in the platforms folder.

Related

Detect internet connection in Electron

Our Electron app needs some configuration files and usually downloads them from our server. In case the client is offline, we don't want him to see any error messages. We are using Electron Download Manager to get the files.
This is how we request the files
try{
DownloadManager.bulkDownload({
urls: links
}, function (error, finished, errors) {
if (error) {
console.log("ERROR: Encountered error during config file download!");
console.log("Finished Files: " + finished);
console.log("Errors: " + errors);
return;
}
console.log("Finished loading all configuration files.");
});
} catch (err){
online_status = false;
console.log("Couldn't get online configuration. Starting app as offline.");
}
With this code the error Uncaught Exception: Error: net::ERR_ADDRESS_UNREACHABLE is thrown, when not connected to the internet.
I tried implementing the official event detection from Electron but as they state:
Such as in cases where the computer is running a virtualization
software that has virtual ethernet adapters that are always
“connected.” Therefore, if you really want to determine the internet
access status of Electron, you should develop additional means for
checking.
Then I went on trying just to ping the server like in this thread but this doesn't work at all for me, it's possible that it doesn't work anymore.
This is a bug in Electron Download Manager, documented in an GitHub Issue like #JeffRSon stated. A pull request is ready for a merge but not merged yet (posted 06.06.2019).
I hope this helps you. I will update this question if it get's merged and works.

How to download files and store them to s3 by nodejs (through heroku)?

I want to know how to download the files to aws-s3 through heroku, and dosen't use the web page.
I'm using wget in Nodejs to download audio files, and wanting to re-encoding them by ffmpeg. Though I have to store the file first, but heroku doesn't provide the space to store.
Then I find the way that heroku can connect with aws-s3, however the sample code is the page for user to upload, and I'm just want to using codes.
This is the code that haven't connected with s3 yet.
const wget = spawn('wget',['-O', 'upload_audio/'+ sender_psid +'.aac', audioUrl]);
//spit stdout to screen
wget.stdout.on('data', function (data) { process.stdout.write(data.toString()); });
// //spit stderr to screen
wget.stderr.on('data', function (data) { process.stdout.write(data.toString()); });
wget.on('close', function (code) {
console.log(process.env.PATH);
const ffmpeg = spawn('ffmpeg',['-i', 'upload_audio/'+ sender_psid +'.aac', '-ar', '16000', 'upload_audio/'+ sender_psid +'.wav', '-y']);
...
});
And it comes the error:
upload_audio/1847432728691358.aac: No such file or directory
...
Error: ENOENT: no such file or directory, open 'upload_audio/1847432728691358.wav'
How can I solve the problem?
Could anyone give some suggest plz?
Maybe won't use s3 can get it?
I don't recommend using S3 until you've tried the NodeJS Static Files API. On the server, that looks like this:
app.use(express.static(path.join(__dirname, 'my_audio_files_folder')));
More on NodeJS's Static Files API available here.
AWS S3 seems to be adding unneeded complexity, but if you have your heart set on it, have a look at this thread.

Cordova web intent Plugin Not working for version 7.0.1

I am using Cordova version 7.0.1,I want to use webintent and when i am trying to install like this
cordova plugin add https://github.com/Initsogar/cordova-webintent.git
i am getting this error
I am trying to recieve the url from the other apps to my cordova app and the code i am following is this one.
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_TEXT, function (url) {
alert(url);
console.log("coming");
}, function() { //Fail
alert ("error");
});
when i am executing i am getting this error
Error: exec proxy not found for :: WebIntent :: getExtra
PS: I know that URL is not working,Is there any other way to install Web Intent
That repository is no longer available.
I could successfully get the plugin from https://github.com/cordova-misc/cordova-webintent

Open MS Office files from Cordova and iOS

I am using Cordova to create applications in iOS (version 10.3). I want to open an office file by using the command
window.open("data:application/msword;base64," + fileContent, "_blank", "location=no");
I use the MIME that can be found here
http://filext.com/faq/office_mime_types.php.
I have installed plugins InAppBrowser, ADALProxy, Cordova-plugin-MS-Files.
My problem is that when the document opens, it is blank, completely empty. I can view other type of files (pdf, images etc) but not Office files (docx, xls, ppt).
Any idea? Am I missing any plugin?
I believe the issue is caused by inAppBrowser not being able to view MS files.
My suggestion is to use the fileOpener2 plugin to open the file with whichever document viewer the user has that is capable of opening MS files.
http://ngcordova.com/docs/plugins/fileOpener2/135
Then you can use something like this:
cordova.plugins.fileOpener2.open(
'YOUR_FILE_URI', // File location or URI
'application/docx', //MIME type
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
This will cause the device to use an application that can handle MS files.
I know it's old question, however I wrote a Cordova plugin to preview office document and most of major file type,
it works on IOS and Android
you can use it from here
https://github.com/mostafa-mansour1/previewAnyFile
to install in your cordova or ionic project
$ cordova plugin add cordova-plugin-preview-any-file --save
then use it in your code like this
PreviewAnyFile.preview("file://filepath/filename.ext");
if the source is base64 string then you need to save it in the device with cordova file plugin (Write to a file) section

How to debug a cordova plugin with your phone?

I use Weinre to get a console from my phone. But on Javascript errors with plugins (contacts, geolocalisation etc...) I get nothing....
I don't know how to push on the console every javascript errors.
How to easily debug your javascript which use a plugin present only on your device ?
Thank you.
You can use the Console Plugin to debug your code in iOS, android, windows phone, etc.
Install the plugin using: $ cordova plugin add org.apache.cordova.console
Then its as simple as using console.log(...); in your javascript files.
If you want to log your geolocation you can do:
var onSuccess = function(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
};
var onError = function(err) {
console.log(error.code);
console.log(error.message);
};
navigator.geolocation.getCurrentPosition(onSuccess, onError);
Then, when you build your app, and emulate, look for this log file in your project:
.../platforms/ios/cordova/console.log

Categories

Resources