3

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.

hhelbawi
  • 151
  • 2
  • 12

3 Answers3

3

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.

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
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.

i-man
  • 558
  • 3
  • 14
0

I'm guessing that the plugin you are using is looking at the mime-type:

(copied from here: What is a correct mime type for docx, pptx etc?)


.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document

Community
  • 1
  • 1
Johannes Ferner
  • 718
  • 7
  • 15