Back

ChooseFile

JS Py
Hello World

ChooseFile opens a file picker for user to select a local file or a file from GoogleDrive, OneDrive or DropBox.

app.ChooseFile( message, type, callback, fldr?, options? )

See Also: ReadFile

Example - Choose File by Mimetype

function OnStart()
{
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    var list = "*/*,application/text,application/apk,application/zip," +
        "audio/mpeg,audio/mp4,audio/ogg,image/png,image/jpeg,text/css," +
        "text/html,text/javascript,text/plain,video/mpeg,video/mp4,video/ogg";

    spnMime = app.CreateSpinner(list);
    lay.AddChild(spnMime);

    btnChoose = app.CreateButton( "Choose File", 0.5, 0.1 );
    btnChoose.SetOnTouch( btnChoose_OnTouch );
    lay.AddChild( btnChoose );

    app.AddLayout( lay );
}

function btnChoose_OnTouch()
{
    app.ChooseFile( "Choose a File", spnMime.GetText(), OnChoose );
}

function OnChoose( file )
{
    alert( "file path: " + file );
}
from native import app

def OnStart():
    global spnMime
    lay = app.CreateLayout( "linear", "VCenter,FillXY" )

    list = "*/*,application/text,application/apk,application/zip," +         "audio/mpeg,audio/mp4,audio/ogg,image/png,image/jpeg,text/css," +         "text/html,text/javascript,text/plain,video/mpeg,video/mp4,video/ogg"

    spnMime = app.CreateSpinner(list)
    lay.AddChild(spnMime)

    btnChoose = app.CreateButton( "Choose File", 0.5, 0.1 )
    btnChoose.SetOnTouch( btnChoose_OnTouch )
    lay.AddChild( btnChoose )

    app.AddLayout( lay )

def btnChoose_OnTouch():
    app.ChooseFile( "Choose a File", spnMime.GetText(), OnChoose )

def OnChoose( file ):
    app.Alert( "file path: " + file )
    Copy     Copy All       Run      
String
String: path to file or folder ( “/absolute/...” or “relative/...” )
String: “file mimetype”
String: comma “,” separated: persist, nodownload
function( path, name )