Check available space for storage

48 views
Skip to first unread message

Luis Zapata

unread,
Apr 25, 2016, 3:09:44 PM4/25/16
to phonegap
I have an app working with phoneapp for android that downloads some extra files and i would like to check if there is enough space available in the internal storage for it, Is there a way to check it? I've been reading documentation and I just found the parameter "estimatedSize" regarding to this, but cannot do much with it, thanks!

Kerri Shotts

unread,
Apr 27, 2016, 3:43:28 PM4/27/16
to phonegap
If you don't need the exact amount of space available, however, you can request a file system of the size you're going to download. If there is insufficient space on the device, the request will fail with error code 10 (QUOTA EXCEEDED_ERR). In the following example, I'm requesting a HUGE file system, which is almost certainly guaranteed to fail for a few years:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 1024*1024*1024*1024,
                         
function success(fs) {
                             alert
("Got file system" + JSON.stringify(fs));
                         
}, function error(e) {
                             alert
("Got error" + JSON.stringify(e));
                         
});
// This is almost certainly going to fail with {code: 10}

I just tried it, and it works. I can't vouch that it will work everywhere or consistently or forever into the future since it doesn't look like it is exposed via the JS interface. So user beware!

On Monday, April 25, 2016 at 2:09:44 PM UTC-5, Luis Zapata wrote:
...

Kerri Shotts

unread,
Apr 27, 2016, 4:26:17 PM4/27/16
to phonegap
Also note the discussion on Cordova issues regarding the method mentioned in the last portion of my message: https://issues.apache.org/jira/browse/CB-6703

Personally, I'd just use the requestFileSystem method for now until the devs actually expose a way of getting the free space.

Kerri Shotts

unread,
Apr 27, 2016, 5:10:18 PM4/27/16
to phonegap
Also, there's a third party plugin for getting exact space available, but I haven't tried it personally: https://www.npmjs.com/package/sqli-cordova-disk-space-plugin

And for completeness-sake, I wrote a blog post about this very issue: https://www.photokandy.com/2016/04/27/quick-tip-is-there-sufficient-storage-space-available-on-the-device/

On Wednesday, April 27, 2016 at 3:26:17 PM UTC-5, Kerri Shotts wrote:
...
Reply all
Reply to author
Forward
0 new messages