Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get selected file size using org.apache.cordova.file

Using org.apache.cordova.file plugin I can selected the file and I get the native path of the file. After that I have to restrict the user to select the file according to there file size. But I can't get that file size. My problem is that I can't get the file Size using that plugin. For this I am using this tutorial.

like image 535
RahulSalvikar Avatar asked Dec 18 '22 23:12

RahulSalvikar


1 Answers

To get file size, you need to access it via metadata as follows:

            window.resolveLocalFileSystemURL(filePath, 
                function (fileSystem) {
                    fileSystem.getFile(fileName, {create: false}, 
                        function (fileEntry) {
                            fileEntry.getMetadata(
                                function (metadata) {
                                    alert(metadata.size); // get file size
                                }, 
                                function (error) {}
                            );
                        }, 
                        function (error) {}
                    );
                }, 
                function (error) {} 
            );     
like image 54
Nakket Avatar answered Dec 28 '22 07:12

Nakket