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 e from here.
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 e from here.
Share Improve this question edited Aug 13, 2015 at 12:15 hhelbawi asked Aug 13, 2015 at 12:04 hhelbawihhelbawi 1512 silver badges13 bronze badges 5- What error do you get? – innuendomaximus Commented Aug 13, 2015 at 12:07
- Verify that the file type is within the supported file formats that you have mentioned. – callmekatootie Commented Aug 13, 2015 at 12:09
- Nothing! I put a console log to log the type of the file but nothing shows up. Whereas when I upload a pdf I have in the console "type = application/pdf". – hhelbawi Commented Aug 13, 2015 at 12:10
- Do you think that ng-file-upload does not support doc or docx types? – hhelbawi Commented Aug 13, 2015 at 12:19
- How did you resolve this issue? – João Martins Commented Jun 2, 2016 at 10:27
3 Answers
Reset to default 3The right MIME types are the following:
.doc -> application/msword
.docx -> application/vnd.openxmlformats-officedocument.wordprocessingml.document
Other MS format MIME types are summarized here.
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'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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745229079a4617596.html
评论列表(0条)