diff --git a/docs/viewer.component.md b/docs/viewer.component.md index 1f22031f41..678a10159b 100644 --- a/docs/viewer.component.md +++ b/docs/viewer.component.md @@ -45,6 +45,7 @@ Using with file url: | --- | --- | --- | --- | | fileNodeId | string | | Node Id of the file to load | | urlFile | string | | If you want to load an external file that does not come from ECM you can use this Url where to load the file | +| urlFileViewer | string | null | Viewer to use with the `urlFile` address (`pdf`, `image`, `media`, `text`). Used when `urlFile` has no filename and extension. | | urlBlob | Blob | | If you want to load a Blob File | | overlayMode | boolean | false | If `true` show the Viewer full page over the present content otherwise will fit the parent div | | showViewer | boolean | true | Hide or show the viewer | diff --git a/lib/core/viewer/components/viewer.component.ts b/lib/core/viewer/components/viewer.component.ts index 9b49e2365d..fe978f0d38 100644 --- a/lib/core/viewer/components/viewer.component.ts +++ b/lib/core/viewer/components/viewer.component.ts @@ -54,6 +54,9 @@ export class ViewerComponent implements OnChanges { @Input() urlFile = ''; + @Input() + urlFileViewer: string = null; + @Input() blobFile: Blob; @@ -176,7 +179,7 @@ export class ViewerComponent implements OnChanges { this.downloadUrl = this.urlFile; this.fileName = this.displayName; - this.viewerType = this.getViewerTypeByExtension(this.extension); + this.viewerType = this.urlFileViewer || this.getViewerTypeByExtension(this.extension); if (this.viewerType === 'unknown') { this.viewerType = this.getViewerTypeByMimeType(this.mimeType); } @@ -328,13 +331,20 @@ export class ViewerComponent implements OnChanges { } /** - * Get the token from the local storage + * Get file extension from the string. + * Supports the URL formats like: + * http://localhost/test.jpg?cache=1000 + * http://localhost/test.jpg#cache=1000 * * @param {string} fileName - file name * @returns {string} file name extension */ getFileExtension(fileName: string): string { - return fileName.split('.').pop().toLowerCase(); + if (fileName) { + const match = fileName.match(/\.([^\./\?\#]+)($|\?|\#)/); + return match ? match[1] : null; + } + return null; } isCustomViewerExtension(extension: string): boolean {