
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
react-simple-file-input
Advanced tools
Simple wrapper for the HTML input tag and HTML5 FileReader API
react-simple-file-input expects a readAs option to indicate how the file should be read. Valid options are:
By default the readAs option is undefined. If left undefined, the file will not be read from disk and only the onChange event will be triggered.
react-simple-file-input supports the following event handlers:
Each receives the native event as the first argument, and the selected file object as the second.
The onChange handler is called whenever the file is changed and occurs before the file is read from disk. It receives a File object as its only argument.
The onCancel handler receives the File object corresponding to the file the user attempted to read from the file system.
If the readAs option is not specified, the file will not be read from disk and only onChange will be triggered. All other events as skipped.
react-simple-file-input provides two props for canceling and aborting file reads
The cancelIf prop accepts a function that receives the File object. If the function is defined and returns a truthy value then the file upload will be cancelled before it begins reading from the filesystem and the onCancel handler is called with the file object.
If defined the abortIf function is executed just before every time the onProgress handler is called. It is passed the native event and the file object as arguments, respectively and if it returns a truthy value it aborts the file read and calls the onAbort handler. The onProgress event is not called if the file read aborts.
All children passed to react-simple-file-input will be nested so when they are clicked the browser's file selection window opens.
var FileInput = require('react-simple-file-input');
var allowedFileTypes = ["image/png", "image/jpeg", "image/gif"];
function fileIsIncorrectFiletype(file){
if (allowedFileTypes.indexOf(file.type) === -1) {
return true;
} else {
return false;
}
}
var Component = React.createClass({
render: function(){
return(
<div>
To upload a file:
<FileInput
readAs='binary'
onLoadStart={this.showProgressBar}
onLoad={this.handleFileSelected}
onProgress={this.updateProgressBar}
cancelIf={fileIsIncorrectFiletype}
onCancel={this.showInvalidFileTypeMessage}
abortIf={this.cancelButtonClicked}
onAbort={this.resetCancelButtonClicked}
>
Click Here
</FileInput>
</div>
);
},
cancelButtonClicked: function(){
return this.state.cancelButtonClicked;
},
resetCancelButtonClicked: function(){
this.setState({ cancelButtonClicked: false });
},
showInvalidFileTypeMessage: function(file){
window.alert("Tried to upload invalid filetype " + file.type);
},
showProgressBar: function(){
this.setState({ progressBarVisible: true});
},
updateProgressBar: function(event){
this.setState({
progressPercent: (event.loaded / event.total) * 100
});
},
handleFileSelected: function(event, file){
this.setState({file: file, fileContents: event.target.result});
}
});
FAQs
Simple wrapper for the HTML input tag and HTML5 FileReader API
The npm package react-simple-file-input receives a total of 15,640 weekly downloads. As such, react-simple-file-input popularity was classified as popular.
We found that react-simple-file-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.