p5.js createFileInput() Function Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The createFileInput() function is used to create an input element with the type of 'file' that can be used by the user to select local files to be used in the sketch. It also supports the selection of multiple files if required. Syntax: createFileInput(callback, multiple) Parameters: This function accepts two parameters as mentioned above and described below: callback: It is the callback function that would be used when the file is loaded. It is an optional parameter. multiple: It is a string which specifies if multiple files are allowed to be selected at once. It can be set to "true" or "false". It is an optional parameter. Return Value: It returns a pointer to the p5.Element holding the created file object. Below examples illustrate the createFileInput() function in p5.js: Example 1: In this example, we will take one file as an input. javascript function setup() { createCanvas(400, 200); textSize(18); text("Click on the file input and select a file.", 20, 20); inputbtn = createFileInput(processFile); inputbtn.position(30, 40); } function processFile(file) { console.log(file); text("The name of the file selected is: "+ file.name, 20, 80); text("The extension of the file selected is: "+ file.subtype, 20, 100); text("The type of the file selected is: "+ file.type, 20, 120); text("The size of the file selected is: "+ file.size, 20, 140); } Output: Example 2: In this example, we will take multiple files as an input. javascript let i = 0; function setup() { createCanvas(500, 200); textSize(18); text("The file input below allows"+ " selecting of multiple files.", 20, 20); inputBtn = createFileInput(processFiles, "true"); inputBtn.position(30, 60); } function processFiles(file) { text("The name of the file selected is: " + file.name, 20, 120 + i); i = i + 20; } Output: Online editor: https://editor.p5js.org/ Environment Setup: https://www.geeksforgeeks.org/javascript/p5-js-soundfile-object-installation-and-methods/ Reference: https://p5js.org/reference/#/p5/createFileInput Create Quiz Comment S sayantanm19 Follow 0 Improve S sayantanm19 Follow 0 Improve Article Tags : JavaScript Web Technologies JavaScript-p5.js Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like