I've had trouble uploading .docx files using AjaxFileUploader...they seemed to be ignored even though "docx" was in AllowedFileTypes.
The problem arises in the following function in AjaxFileUpload.js, where it turns out that file.type of a word document (.docx file) is "application/vnd.openxmlformats-officedocument.wordprocessingml.document" and it's actually using this as a comparison against the list of file types.
```
_html5AddFileInQueue: function (files) {
debugger;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var fileType;
if (file.type != '') {
fileType = file.type.substring(file.type.lastIndexOf('/') + 1);
}
else {
fileType = file.name.substring(file.name.lastIndexOf('.') + 1);
}
if (this._validateFileType(fileType)) {
var uploadableFile = new Object();
uploadableFile.file = file;
uploadableFile.id = Sys.Extended.UI.AjaxFileUpload.utils.generateGuid();
this._addToQueue(uploadableFile);
}
else {
}
}
}
```
I'm not sure when using file.type (rather then the end of file.name) would be appropriate, but simply removing the file.type comparison seems to fix the problem for me and lets me upload .docx files as expected.
```
_html5AddFileInQueue: function (files) {
debugger;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var fileType;
fileType = file.name.substring(file.name.lastIndexOf('.') + 1);
if (this._validateFileType(fileType)) {
var uploadableFile = new Object();
uploadableFile.file = file;
uploadableFile.id = Sys.Extended.UI.AjaxFileUpload.utils.generateGuid();
this._addToQueue(uploadableFile);
}
else {
}
}
},
```
Comments: Maybe this can help somebody, I have applied this JS workaround: ``` <script type="text/javascript"> function FixUploadControlExtender() { if (!Sys) return; if (!Sys.Application) return; var els = Sys.Application.getComponents(); if (!els) return; for (i = 0; i < els.length; i++) { if (typeof els[i]._allowedFileTypes !== "undefined") { els[i]._allowedFileTypes = 'gif,png,jpg,doc,docx,txt'; } } } if (Sys) Sys.Application.add_load(FixUploadControlExtender); </script> ``` Obviously you must change the allowedFileTypes assignment as you need.
The problem arises in the following function in AjaxFileUpload.js, where it turns out that file.type of a word document (.docx file) is "application/vnd.openxmlformats-officedocument.wordprocessingml.document" and it's actually using this as a comparison against the list of file types.
```
_html5AddFileInQueue: function (files) {
debugger;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var fileType;
if (file.type != '') {
fileType = file.type.substring(file.type.lastIndexOf('/') + 1);
}
else {
fileType = file.name.substring(file.name.lastIndexOf('.') + 1);
}
if (this._validateFileType(fileType)) {
var uploadableFile = new Object();
uploadableFile.file = file;
uploadableFile.id = Sys.Extended.UI.AjaxFileUpload.utils.generateGuid();
this._addToQueue(uploadableFile);
}
else {
}
}
}
```
I'm not sure when using file.type (rather then the end of file.name) would be appropriate, but simply removing the file.type comparison seems to fix the problem for me and lets me upload .docx files as expected.
```
_html5AddFileInQueue: function (files) {
debugger;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var fileType;
fileType = file.name.substring(file.name.lastIndexOf('.') + 1);
if (this._validateFileType(fileType)) {
var uploadableFile = new Object();
uploadableFile.file = file;
uploadableFile.id = Sys.Extended.UI.AjaxFileUpload.utils.generateGuid();
this._addToQueue(uploadableFile);
}
else {
}
}
},
```
Comments: Maybe this can help somebody, I have applied this JS workaround: ``` <script type="text/javascript"> function FixUploadControlExtender() { if (!Sys) return; if (!Sys.Application) return; var els = Sys.Application.getComponents(); if (!els) return; for (i = 0; i < els.length; i++) { if (typeof els[i]._allowedFileTypes !== "undefined") { els[i]._allowedFileTypes = 'gif,png,jpg,doc,docx,txt'; } } } if (Sys) Sys.Application.add_load(FixUploadControlExtender); </script> ``` Obviously you must change the allowedFileTypes assignment as you need.