From 5f96d3d25971dd9044031f2293e039712563cee4 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 13 Feb 2019 09:29:53 +0100 Subject: [PATCH] MOBILE-2869 core: Support '*' as accepted file types --- src/components/attachments/attachments.ts | 4 +++- src/core/fileuploader/providers/fileuploader.ts | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/attachments/attachments.ts b/src/components/attachments/attachments.ts index a44eb6bb3..03ada9d5d 100644 --- a/src/components/attachments/attachments.ts +++ b/src/components/attachments/attachments.ts @@ -77,7 +77,9 @@ export class CoreAttachmentsComponent implements OnInit { this.maxSubmissionsReadable = String(this.maxSubmissions); } - if (this.acceptedTypes && this.acceptedTypes.trim()) { + this.acceptedTypes = this.acceptedTypes && this.acceptedTypes.trim(); + + if (this.acceptedTypes && this.acceptedTypes != '*') { this.fileTypes = this.fileUploaderProvider.prepareFiletypeList(this.acceptedTypes); } } diff --git a/src/core/fileuploader/providers/fileuploader.ts b/src/core/fileuploader/providers/fileuploader.ts index 753b4bf21..a43b4d3b4 100644 --- a/src/core/fileuploader/providers/fileuploader.ts +++ b/src/core/fileuploader/providers/fileuploader.ts @@ -333,9 +333,16 @@ export class CoreFileUploaderProvider { * Parse filetypeList to get the list of allowed mimetypes and the data to render information. * * @param {string} filetypeList Formatted string list where the mimetypes can be checked. - * @return {{info: any[], mimetypes: string[]}} Mimetypes and the filetypes informations. + * @return {{info: any[], mimetypes: string[]}} Mimetypes and the filetypes informations. Undefined if all types supported. */ prepareFiletypeList(filetypeList: string): { info: any[], mimetypes: string[] } { + filetypeList = filetypeList && filetypeList.trim(); + + if (!filetypeList || filetypeList == '*') { + // All types supported, return undefined. + return undefined; + } + const filetypes = filetypeList.split(/[;, ]+/g), mimetypes = {}, // Use an object to prevent duplicates. typesInfo = [];