forked from valor-software/ng2-file-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 3 commits.
# The first commit's message is: feat(uploader): huge uploader update - creted uploader options - added `file type` support - added headers to xhr - rename FileUploaderSettings => FileUploaderOptionsInterface - added public methods set Options - created filter from set options - added demo component # The 2nd commit message will be skipped: # rename FileUploaderSettings => FileUploaderOptionsInterface # The 3rd commit message will be skipped: # added public method setOptions
- Loading branch information
Showing
5 changed files
with
372 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
export class FileType { | ||
/* MS office */ | ||
static mime_doc = [ | ||
'application/msword', | ||
'application/msword', | ||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | ||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template', | ||
'application/vnd.ms-word.document.macroEnabled.12', | ||
'application/vnd.ms-word.template.macroEnabled.12' | ||
]; | ||
static mime_xsl = [ | ||
'application/vnd.ms-excel', | ||
'application/vnd.ms-excel', | ||
'application/vnd.ms-excel', | ||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template', | ||
'application/vnd.ms-excel.sheet.macroEnabled.12', | ||
'application/vnd.ms-excel.template.macroEnabled.12', | ||
'application/vnd.ms-excel.addin.macroEnabled.12', | ||
'application/vnd.ms-excel.sheet.binary.macroEnabled.12' | ||
]; | ||
static mime_ppt = [ | ||
'application/vnd.ms-powerpoint', | ||
'application/vnd.ms-powerpoint', | ||
'application/vnd.ms-powerpoint', | ||
'application/vnd.ms-powerpoint', | ||
'application/vnd.openxmlformats-officedocument.presentationml.presentation', | ||
'application/vnd.openxmlformats-officedocument.presentationml.template', | ||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow', | ||
'application/vnd.ms-powerpoint.addin.macroEnabled.12', | ||
'application/vnd.ms-powerpoint.presentation.macroEnabled.12', | ||
'application/vnd.ms-powerpoint.presentation.macroEnabled.12', | ||
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' | ||
]; | ||
|
||
/* PSD */ | ||
static mime_psd = [ | ||
'image/photoshop', | ||
'image/x-photoshop', | ||
'image/psd', | ||
'application/photoshop', | ||
'application/psd', | ||
'zz-application/zz-winassoc-psd' | ||
]; | ||
|
||
/* Compressed files */ | ||
static mime_compress = [ | ||
'application/x-gtar', | ||
'application/x-gcompress', | ||
'application/compress', | ||
'application/x-tar', | ||
'application/x-rar-compressed', | ||
'application/octet-stream' | ||
]; | ||
|
||
static getMimeClass(file) { | ||
let mimeClass = 'application'; | ||
if (this.mime_psd.indexOf(file.type) !== -1) { | ||
mimeClass = 'image'; | ||
} else if (file.type.match('image.*')) { | ||
mimeClass = 'image'; | ||
} else if (file.type.match('video.*')) { | ||
mimeClass = 'video'; | ||
} else if (file.type.match('audio.*')) { | ||
mimeClass = 'audio'; | ||
} else if (file.type === 'application/pdf') { | ||
mimeClass = 'pdf'; | ||
} else if (this.mime_compress.indexOf(file.type) !== -1) { | ||
mimeClass = 'compress'; | ||
} else if (this.mime_doc.indexOf(file.type) !== -1) { | ||
mimeClass = 'doc'; | ||
} else if (this.mime_xsl.indexOf(file.type) !== -1) { | ||
mimeClass = 'xls'; | ||
} else if (this.mime_ppt.indexOf(file.type) !== -1) { | ||
mimeClass = 'ppt'; | ||
} | ||
if (mimeClass === 'application') { | ||
mimeClass = this.fileTypeDetection(file.name); | ||
} | ||
|
||
|
||
return mimeClass; | ||
} | ||
|
||
|
||
static fileTypeDetection(inputFilename) { | ||
let types = { | ||
'jpg': 'image', | ||
'jpeg': 'image', | ||
'tif': 'image', | ||
'psd': 'image', | ||
'bmp': 'image', | ||
'png': 'image', | ||
'nef': 'image', | ||
'tiff': 'image', | ||
'cr2': 'image', | ||
'dwg': 'image', | ||
'cdr': 'image', | ||
'ai': 'image', | ||
'indd': 'image', | ||
'pin': 'image', | ||
'cdp': 'image', | ||
'skp': 'image', | ||
'stp': 'image', | ||
'3dm': 'image', | ||
'mp3': 'audio', | ||
'wav': 'audio', | ||
'wma': 'audio', | ||
'mod': 'audio', | ||
'm4a': 'audio', | ||
'compress': 'compress', | ||
'rar': 'compress', | ||
'7z': 'compress', | ||
'lz': 'compress', | ||
'z01': 'compress', | ||
'pdf': 'pdf', | ||
'xls': 'xls', | ||
'xlsx': 'xls', | ||
'ods': 'xls', | ||
'mp4': 'video', | ||
'avi': 'video', | ||
'wmv': 'video', | ||
'mpg': 'video', | ||
'mts': 'video', | ||
'flv': 'video', | ||
'3gp': 'video', | ||
'vob': 'video', | ||
'm4v': 'video', | ||
'mpeg': 'video', | ||
'm2ts': 'video', | ||
'mov': 'video', | ||
'doc': 'doc', | ||
'docx': 'doc', | ||
'eps': 'doc', | ||
'rtf': 'doc', | ||
'txt': 'doc', | ||
'odt': 'doc', | ||
'rtf': 'doc', | ||
'ppt': 'ppt', | ||
'pptx': 'ppt', | ||
'pps': 'ppt', | ||
'ppsx': 'ppt', | ||
'odp': 'ppt' | ||
}; | ||
|
||
let chunks = inputFilename.split('.'); | ||
if (chunks.length < 2) { | ||
return 'application'; | ||
} | ||
let extension = chunks[chunks.length - 1].toLowerCase(); | ||
if (types[extension] === undefined) { | ||
return 'application'; | ||
} else { | ||
return types[extension]; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<label class="btn btn-primary">Select File | ||
<input type="file" (change)="onChange($event)" [multiple]="multiple" style="display: none;"/> | ||
</label> |
Oops, something went wrong.