Fixed file upload bug

This commit is contained in:
Peter Zimon 2022-11-16 14:20:08 +01:00 committed by Sam Lord
parent 3eaa00bddb
commit 739efa5a36

View File

@ -18,12 +18,8 @@ export default class ContentFileSelect extends Component {
@action
fileSelected(fileList) {
console.log('File list: ' + JSON.stringify(fileList));
let [file] = Array.from(fileList);
console.log('Validating file: ' + JSON.stringify(file));
try {
this._validateFileType(file);
this.error = null;
@ -32,8 +28,6 @@ export default class ContentFileSelect extends Component {
return;
}
console.log('Setting file to: ' + JSON.stringify(file));
this.args.setFile(file);
}
@ -67,14 +61,16 @@ export default class ContentFileSelect extends Component {
event.preventDefault();
this.dragClass = null;
if (event.dataTransfer.files) {
console.log("dropped: ", event.dataTransfer.files);
this.fileSelected(event.dataTransfer.files);
}
}
_validateFileType(file) {
console.log(file);
let [, extension] = (/(?:\.([^.]+))?$/).exec(file.name);
if (extension.toLowerCase() !== 'json' || extension.toLowerCase() !== 'zip') {
if (extension.toLowerCase() !== 'json' && extension.toLowerCase() !== 'zip') {
throw new UnsupportedMediaTypeError({
message: 'The file type you uploaded is not supported'
});