Ionic native file opener 2 error class not found - ionic-framework

I receive error when trying to open a file Class not found
.ts
open(){
this.platform.ready().then(() => {
this.fileOpener.open(this.entry.nativeURL, this.attachment.mime).then(() => {
console.log('file opened')
}, err => {
console.log('error open file: ', err)
});
});
}
this.entry.nativeURL is the download result using File Transfer
nativeURL: file:///storage/emulated/0/Download/someFile.docx
this.fileTransfer.download(url, this.storageDirectory + this.attachment.fileName, trustAllHosts).then((entry) => {
console.log('entry: ', entry);
this.entry = entry;
}
this.attachment.mime: application/vnd.openxmlformats-officedocument.wordprocessingml.document
I also tried application/pdf for a pdf file , didn't work

Its working... the problem was in running the app live --livereload

Related

How to solve File (.pdf) path directory doesn't exist error if I select file (.pdf) from mobile download folder in ionic

I want to upload the pdf file on our server using the file-chooser Cordova plugin. I had success in the file selection but after the file selection I tried to upload on the server but received the error "directory doesn't exist".
var filter = { "mime": "application/pdf" };
this.fileChooser.open(filter)
.then(url => {
console.log('fileChooser:',url);
this.filePath.resolveNativePath(url)
.then(filePath => {
console.log('saif file pathhh',filePath);
let correctPath = url.substr(0,url.lastIndexOf("/") + 1);
let currentName = filePath.substring(filePath.lastIndexOf('/') + 1);
this.file.checkDir(this.file.externalDataDirectory, correctPath).then(_ => console.log('Directory exists')).catch(err =>
console.log('Directory doesnt exist'));
let _filePath = filePath;
let resPath = this.pathForImage(_filePath);
let newEntry = {
name: currentName,
path: resPath,
filePath: _filePath,
comparessedPath: _filePath,
};
this.startUpload(newEntry, index, field_id);
})
.catch(err => console.log('saif file pathhh errorrr',err));
})
.catch(e => {
console.log('saif file pathhh errorrr catchhh',e);
});
I want to real path of selected pdf file by using file-chooser cordova plugin

VuexFire Synchronization with bind not working

I'm currently using VuexFire to bind the Cloud Firestore to my Vuex State. I'm having some issues getting it to work, any help would be appreciated.
What I'm currently doing is the following:
Vue.js File:
methods:{
...mapActions("comments", ['bindArticleComments']),
},created(){
this.bindArticleComments()
},
actions/comments file
export const bindArticleComments = firestoreAction(({ bindFirestoreRef }) => {
return bindFirestoreRef('articleComments', collectionRef('comments'))
})
firebase services file
export const collectionRef = (collectionName) => {
return firestore().collection(collectionName)
}
What is strange about this is that I'm already doing the same procedure for a different Vuex state field. There it seems to be working without an issue. Is there anything that anyone thinks I might not be doing properly?
Strangely i got it working , although i'm struggling to understand how and why it's working.In my Vue js file i placed the this.bindArticleComments() after downloading the data and at creation.
methods:{
downloadComments(){
const { articlesCommentRef } = this.$fb
articlesCommentRef(this.loadedArticle.id).get()
.then(querySnapshot => {
this.setArticleComments(querySnapshot.docs.map((doc) => doc.data()))
this.bindArticleComments(this.loadedArticle.id)})
.catch(error => console.log("Error getting documents: ", error))
.finally(() => {this.$q.loading.hide()})
}
},
created(){
this.bindArticleComments(this.loadedArticle.id)
},
mounted(){
this.downloadComments()
}

Cordova Ionic Native File plugin - Where does it store the files in iOS?

I been trying to save a file on iOS. Right now I been running through Xcode right to my phone.
When I run the app it says that is saved successfully. But I don’t see any file when I use a file manager app like FileApp, FileManager, iCloud and the Apple crappy Files app.
My question is that I heard from a web search that in order to save the file iOS creates a sandbox folder for the app.
If I been saving it to this.file.documentDirectory, how can a user open it in let’s say Pages or Numbers apps? (You know Apple’s Word and Excel replacement for the uninitiated.)
Here’s the code.
writeToIOS(opts : {
fileName: string,
text: any
}) : Promise < IResponse < any >> {
let response: IResponse < boolean > = {
success: false,
error: '',
data: false
};
const options: IWriteOptions = {
replace: true
};
return new Promise((resolve, reject) => {
const path = this.file.documentsDirectory;
const directory = 'Attendance Log';
this
.file
.checkDir(path, directory)
.then(res => {
this
.file
.writeFile(path + directory, opts.fileName, opts.text, options)
.then(res => {
response = {
...response,
success: true,
error: res,
data: res
};
resolve(response);
})
.catch(error => reject(error));
})
.catch(() => {
this
.file
.createDir(path, directory, true)
.then(directory => {
this
.file
.writeFile(path + directory.name, opts.fileName, opts.text, options)
.then(res => {
response = {
...response,
success: true,
error: res,
data: res
};
resolve(response);
})
.catch(error => reject(error));
})
.catch(error => reject(error));
});
});
}
EDIT:
What the client/user should do is be able to choose the file and open it in his/her favorite app. That being a File Manager app or a Writer or Spreadsheet app.
I don't have too much experience with iOS, but I think you have chosen good dir.
cordova.file.documentsDirectory - Files private to the app, but that
are meaningful to other application (e.g. Office files). Note that for
OSX this is the user's ~/Documents directory. (iOS, OSX)
In iOS i would search /var/mobile/Applications/<UUID>/Documents
This is using the cordova-plugin-fileopener2 in conjuction with ionic native file opener:
const options = {
replace: true
};
const path = this.file.documentsDirectory;
const directory = 'Attendance Log';
this.file
.checkDir(path, directory)
.then(res => {
this.file
.writeFile(path + directory, opts.fileName, opts.text, options)
.then(res => {
this.fileOpener
.open(`${path}${directory}/${opts.fileName}` , 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
.then(() => ...)
.catch(error => ...);
})
.catch(error => ...);

cordova camera plugin issue with FILE_URI

I am using IONIC 3.7.0 in my current project. In one requirement I need to use cordova camera plugin to take photo uri from image gallery. Every time when I am trying to get the URI , I get the data_uri which is base64 long string.
I only need the file_uri of image to go further. Please suggest.
var options = {
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
destinationType: Camera.DestinationType.FILE_URI
};
Camera.getPicture(options)
.then((imageData) => {
console.log(imageData);
this.fileToUpload = imageData;
const base64Image = "data:image/jpeg;base64," + imageData;
this.preloadImage._img.src = base64Image;
this.codeservice.doProfileImageUpload(base64Image)
.subscribe(res => {
if(res.length()>0){
console.log('updated');
}
})
}, (err) => {
console.log(err);
});

Getting Time-Out Error While Posting Data

js.I am trying to create a file upload using node.js and mongodb.I am getting timeout error in posting data.The code that i use is:
app.post('/photos/new', function(req, res) {
var photo = new Photo();
req.form.complete(function(err, fields, files) {
if(err) {
next(err);
} else {
ins = fs.createReadStream(files.file.path);
ous = fs.createWriteStream(__dirname + '/static/uploads/photos/' + files.file.filename);
util.pump(ins, ous, function(err) {
if(err) {
next(err);
} else { photos.save({
filename: files.file.filename,
file: files.file.path
}, function(error, docs) {
res.redirect('/photos');
});
}
});
//console.log('\nUploaded %s to %s', files.photo.filename, files.photo.path);
//res.send('Uploaded ' + files.photo.filename + ' to ' + files.photo.path);
}
});
});
I get the following error when i click on the submit button.
Error: Timeout POST /photos/new
at Object._onTimeout (/home/nodeexmple/node_modules/connect-timeout/index.js:12:22)
at Timer.ontimeout (timers_uv.js:84:39)
Please help.
see this answer...
Error: parser error, 0 of 4344 bytes parsed (Node.js)
Also u can use req.clearTimeout() as suggested above by alessioalex.
I belive this part of your code is creating problems that u should avoid.
photos.save({
filename: files.file.filename,
file: files.file.path
}, function(error, docs) {
res.redirect('/photos');
});
Instead use like this:
var post = new Post();
post.filename=files.file.filename;
post.file=files.file.path;
And then something like this:
post.save(function(err) {
if (err)
return postCreationFailed();
req.flash('info', 'photos Succesfully Uploaded');
res.redirect('were u want to redirect');
});
Hope this solves your issue.
You are using the connect-timeout module so that is shows a message to your users in case the page takes more than X seconds to load (server-side).
It's obvious that the upload page might be taking more than that, so what you should do in your upload route is to clear the timeout like this:
app.post('/photos/new', function(req, res) {
req.clearTimeout();
...
Read more about connect-timeout on its github page.