JavaScript Unable to upload .doc or .docx file

I am trying to upload doc or docx files in my application :

The view :

<div class="col-xs-12">
    <input type="file" ng-file-select="onFileSelect($files)"/>
    <table>
        <td ng-repeat="file in files">{{ file.name }} </td>
    </table>
</div>

The ctrl :

controller: ['$scope', '$modalInstance', 'rule', '$upload', '$resource', function (modalScope, modalInstance, originalRule, $upload, $resource) {
                modalScope.isLoaded = true;
                modalScope.files = [];
                modalScope.onFileSelect = function ($files) {           
                var maxSizeString = '10 Mo';
                var maxSizeValue = 10 * 1024 * 1024; // 10Mo 
                var supportedFileFormat = ['image/gif', //
                        'image/jpeg', //
                        'image/png', //
                        'image/tiff',//
                        'image/svg+xml', //
                        'application/pdf',//
                        'application/doc',//
                        'application/docx',//
                    ];

                 $.each($files, function (index, file) {
                      if (_.contains(supportedFileFormat, file.type)) {
                          if (file.size > maxSizeValue) { //10Mo
                                modalScope.fileUploaded = false;
                           } else {
                                modalScope.fileUploaded = true;
                                modalScope.files.push(file);
                            }
                      } else {
                            modalScope.fileUploaded = false;
                        }
                    });
                };

I can upload images or .pdf but not .doc or .docx.. What am I doing wrong? Note that I am using the version 1.3.1 of ng-file-upload. Can't upgrade to the 6.x but I don't think that the issue come from here.

Answer:1

The right MIME types are the following:

.doc  -> application/msword
.docx -> application/vnd.openxmlformats-officedocument.wordprocessingml.document

Other MS format MIME types are summarized here.

Answer:2

The correct MIME types for .doc and .docx are listed as: .doc -> application/msword .docx -> application/vnd.openxmlformats-officedocument.wordprocessingml.document

So you should add those two MIME types to your supportedFileFormat variable and that will allow .doc files to be upload.

.docx files are actually interpreted by your app as MIME type application/zip, because .docx files are actually zipped up XML files.

 var supportedFileFormat = ['image/gif', //
                    'image/jpeg', //
                    'image/png', //
                    'image/tiff',//
                    'image/svg+xml', //
                    'application/pdf',//
                    'application/zip',//
                    'application/msword',//
                ];

Changing the last two lines in you supportedFileFormat variable to the ones above should solve your problem.

Answer:3

I am trying to execute jQuery Ajax request with the following code: $.ajax({ url: '<MY_URL>', type: 'POST', contentType: 'application/json;charset=UTF-8', data: JSON.stringify(...

I am trying to execute jQuery Ajax request with the following code: $.ajax({ url: '<MY_URL>', type: 'POST', contentType: 'application/json;charset=UTF-8', data: JSON.stringify(...

  1. jquery ajax not working
  2. jquery not working ajax loaded content

I have a problem with my site, it's based on Joomla 2.5.16 I will try to explain my problem as good as possible. On my site i have a zipcode checker, were people can check the availability of fiber ...

I have a problem with my site, it's based on Joomla 2.5.16 I will try to explain my problem as good as possible. On my site i have a zipcode checker, were people can check the availability of fiber ...

I'm using the following filter to remove accents from the word inputed by the user on an input field, and then use the resulting string on the filter. .filter('removeAcentos', function(){ ...

I'm using the following filter to remove accents from the word inputed by the user on an input field, and then use the resulting string on the filter. .filter('removeAcentos', function(){ ...

  1. angularjs filter remove item from array
  2. angular filter remove duplicates
  3. angular filter remove spaces
  4. angular filter remove leading zeros
  5. angular filter remove html tags
  6. angular filter remove
  7. angular filter remove decimal
  8. angular filter remove underscore
  9. angular filter remove characters
  10. angular 6 filter remove item from array
  11. angular number filter remove comma
  12. angularjs remove filter
  13. angular kendo grid filter remove

I am trying to remove elements of an array which contains either Groups(containing shapes) or simply Shapes(line, Rect, Circle etc) as its elements. My function is something like below: ...

I am trying to remove elements of an array which contains either Groups(containing shapes) or simply Shapes(line, Rect, Circle etc) as its elements. My function is something like below: ...