Static p5_sys::global::createFileInput[][src]

pub static createFileInput: CreateFileInputInternalType
Expand description

Creates an input element in the DOM of type 'file'. This allows users to select local files for use in a sketch.

Examples

let input;
let img;

function setup() {
  input = createFileInput(handleFile);
  input.position(0, 0);
}

function draw() {
  background(255);
  if (img) {
    image(img, 0, 0, width, height);
  }
}

function handleFile(file) {
  print(file);
  if (file.type === 'image') {
    img = createImg(file.data, '');
    img.hide();
  } else {
    img = null;
  }
}

Parameters

callback callback function for when a file is loaded

multiple? optional, to allow multiple files to be selected