I use the following syntax:
var filecontent = plugins.file.showFileOpenDialog(0, null, false, ‘pdf’)
It opens a dialog where you can select a file.
How can I check if the file that is selected, is a .pdf file?
I use the following syntax:
var filecontent = plugins.file.showFileOpenDialog(0, null, false, ‘pdf’)
It opens a dialog where you can select a file.
How can I check if the file that is selected, is a .pdf file?
Hi Leendert,
plugins.file.showFileOpenDialog will return you the file Path. If you want to choose only files with .pdf extension, then you can do that by passing to the last argument, as an array(I guess). That will filter out all the .pdf files. You can also check the file extension from the file path.
I pass the argument pdf, but the user can still change in the dialog the files of type to all files. I now check the extention from the filepath like you’ve said. Thanks for your help!
Leendert:
I pass the argument pdf, but the user can still change in the dialog the files of type to all files.
So, Do you want to restrict the all files type?
Hmmm…May be It’s not possible, It is the by default one(I am not Sure, I am just thinking). May be someone can help.
just check the return value if its ends with .pdf
maybe better is to check the content type, to check is it really a pdf.
currently you have to do that through the image plugin:
var test = plugin.image.getImage(file);
var contentType = test.getContentType();//“application/pdf”
i created an extra method on JSFile itself: getContentType() that is way quicker as going through the image plugin.