3

我正在尝试在我的应用程序中上传 doc 或 docx 文件:

风景 :

<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>

的 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;
                        }
                    });
                };

我可以上传图片或 .pdf 但不能上传 .doc 或 .docx .. 我做错了什么?请注意,我使用的是 ng-file-upload 版本 1.3.1。无法升级到 6.x,但我认为问题不是来自这里。

4

3 回答 3

3

正确的 MIME 类型如下:

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

此处总结了其他 MS 格式的 MIME 类型。

于 2015-08-13T12:19:48.527 回答
2

.doc 和 .docx 的正确 MIME 类型列为: .doc -> application/msword .docx -> application/vnd.openxmlformats-officedocument.wordprocessingml.document

因此,您应该将这两种 MIME 类型添加到您的 supportedFileFormat 变量中,这样就可以上传 .doc 文件。

.docx 文件实际上被您的应用程序解释为 MIME 类型的 application/zip,因为 .docx 文件实际上是压缩的 XML 文件。

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

将supportedFileFormat 变量中的最后两行更改为上述内容应该可以解决您的问题。

于 2016-03-25T05:21:10.963 回答
0

我猜您正在使用的插件正在查看 mime 类型:

(从这里复制:docx、pptx 等的正确 mime 类型是什么?


.docx 应用程序/vnd.openxmlformats-officedocument.wordprocessingml.document

于 2015-08-13T12:22:19.453 回答