Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.state.fileArray.pop()
}
this.setState({
hasImages: true
})
this.state.tagArray = []
this.state.tagArray.push({
key: 1,
label: 'Image'
})
this.setState(this.state)
// Checks for documents
} else if (accepts(file, '.txt') || (accepts(file, '.docx')) ||
accepts(file, '.odt') || accepts(file, '.pages') ||
accepts(file, '.pdf') || accepts(file, '.pptx') ||
accepts(file, '.keynote') || accepts(file, '.doc') ||
accepts(file, '.odp') || accepts(file, '.ppt') ||
accepts(file, '.ods') || accepts(file, '.xlsx') ||
accepts(file, '.xls') || accepts(file, '.html')) {
this.setState({
uploadedFileType: 'document'
})
// USING 1 FILE INSTEAD OF MULTIPLE UPLOAD CAPABILITIES
this.state.docArray[0] = {
file: file,
key: this.state.docArray.length + 1,
uri: this.state.uploadedFileUri
}
if (this.state.imgArray[0]) {
this.state.imgArray.pop()
}
}
if (this.state.fileArray[0]) {
this.state.fileArray.pop()
}
this.setState({
hasImages: true
})
this.state.tagArray = []
this.state.tagArray.push({
key: 1,
label: 'Image'
})
this.setState(this.state)
// Checks for documents
} else if (accepts(file, '.txt') || (accepts(file, '.docx')) ||
accepts(file, '.odt') || accepts(file, '.pages') ||
accepts(file, '.pdf') || accepts(file, '.pptx') ||
accepts(file, '.keynote') || accepts(file, '.doc') ||
accepts(file, '.odp') || accepts(file, '.ppt') ||
accepts(file, '.ods') || accepts(file, '.xlsx') ||
accepts(file, '.xls') || accepts(file, '.html')) {
this.setState({
uploadedFileType: 'document'
})
// USING 1 FILE INSTEAD OF MULTIPLE UPLOAD CAPABILITIES
this.state.docArray[0] = {
file: file,
key: this.state.docArray.length + 1,
uri: this.state.uploadedFileUri
}
if (this.state.imgArray[0]) {
acceptsSelectedFiles: Array.from(items).every(item => accepts(item, accept))
})
return uploaders.find(uploader => {
return (
is.type(uploader.type, type) &&
accept(file, uploader.accepts) &&
accept(file, get(type.options, 'accept') || '')
)
})
}
_handleSelectPassportFile({target}) {
let gAgent = new GraphAgent()
let file = target.files[0]
if (!accepts(file, 'image/*')) {
this.setState({
error: 'Invalid file type'
})
} else {
this.setState({
loadingPassportPhoto: true
})
this.setState({
error: null,
passportFile: file
})
gAgent.storeFile(null, this.state.storage, file, true).then((res) => {
this.setState({
loadingPassportPhoto: false
})
this.setState({passportImgUri: res})
_handleSelectFile({target}) {
let file = target.files[0]
if (!accepts(file, 'image/*')) {
this.setState({
error: 'Invalid file type'
})
} else {
this.setState({
loadingDisplayPhoto: true
})
this.setState({
error: null,
file: file
})
}
},
return uploaders.find(uploader => {
return (
is.type(uploader.type, type) &&
accept(file, uploader.accepts) &&
accept(file, get(type.options, 'accept') || '')
)
})
}
_handleFileUpload({target}) {
if (this.state.uploadedFile) {
this._handleRemoveFile()
}
const file = target.files[0]
this.setState({
uploadedFile: file
})
if (accepts(file, 'image/*')) {
this.setState({
uploadedFileType: 'image'
})
this._handleImagePreview(file)
} else if (accepts(file, '.txt') || (accepts(file, '.docx')) ||
accepts(file, '.odt') || accepts(file, '.pages') ||
accepts(file, '.pdf') || accepts(file, '.pptx') ||
accepts(file, '.keynote') || accepts(file, '.doc') ||
accepts(file, '.odp') || accepts(file, '.ppt') ||
accepts(file, '.ods') || accepts(file, '.xlsx') ||
accepts(file, '.xls') || accepts(file, '.html')) {
this.setState({
uploadedFileType: 'document'
})
} else {
this.setState({
uploadedFileType: 'miscFile'
})
}
this._autofillWithFilename(file)
},
export function fileAccepted(file, accept) {
return file.type === 'application/x-moz-file' || accepts(file, accept)
}
handleFile = event => {
const files = event.target.files;
if (files.length === 1) {
const file = files[0];
if (!this.props.accept || accepts({
type: file.type,
name: file.name,
}, this.props.accept)) {
this.setState({fileName: file.name});
this.props.input.onChange(file);
return;
}
}
this.setState({fileName: undefined});
this.props.input.onChange(null);
}