DocumentPicker

API Reference: Device.DocumentPicker

DocumentPicker component allows you to select a file from your device to the application. While picking documents you can restrict the selection with following file types; Pdf, Audio, Image, Plain Text and All Files.

File selector:

Files are selected from file explorer/manager app. Please notice that if there is no file explorer app installed on the device, then the picker operation may fail.

JavaScript
JavaScript
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const FlexLayout = require('sf-core/ui/flexlayout');
const Color = require('sf-core/ui/color');
const Button = require('sf-core/ui/button');
const DocumentPicker = require("sf-core/device/documentpicker");
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
this.headerBar.visible = false;
}
});
this.layout.flexDirection = FlexLayout.FlexDirection.ROW;
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
const page = this;
var myButton = new Button({
width: 100,
height: 50,
text: "Button",
textColor:Color.BLACK,
backgroundColor: Color.create("#00A1F1"),
onPress: function() {
DocumentPicker.pick({
page,
type: [DocumentPicker.Types.ALLFILES],
onSuccess: function (file) {
console.log("onSuccess : ",file.path);
},
onCancel: function () {
console.log("onCancel");
}
});
}
});
this.layout.addChild(myButton);
}
);
module.exports = Page1;