diff --git a/src/ios/FileViewerErrors.swift b/src/ios/FileViewerErrors.swift index fbaa3e9..84d3f07 100644 --- a/src/ios/FileViewerErrors.swift +++ b/src/ios/FileViewerErrors.swift @@ -14,6 +14,7 @@ enum FileViewerErrors: String, Error { case invalidURL = "The URL you are trying to open is malformed" case invalidEmptyURL = "Path of the file to open is either null or empty" case downloadFailed = "The download failed" + case missingFileExtension = "The file has no extension" } extension FileViewerErrors : LocalizedError { diff --git a/src/ios/FileViewerPlugin.swift b/src/ios/FileViewerPlugin.swift index 6899f3f..591301d 100644 --- a/src/ios/FileViewerPlugin.swift +++ b/src/ios/FileViewerPlugin.swift @@ -22,6 +22,10 @@ class FileViewerPlugin { if let url = urlString { if let file = URL.init(string: url) { + + let fileName = file.lastPathComponent + guard fileName.contains(".") else { throw FileViewerErrors.missingFileExtension } + guard FileManager.default.fileExists(atPath: file.path) else { throw FileViewerErrors.fileDoesNotExist } if let viewController = rootViewController { @@ -40,7 +44,7 @@ class FileViewerPlugin { return completion({ throw FileViewerErrors.invalidURL }) } - if let fileUrl = URL(string: url), let viewController = rootViewController { + if let fileUrl = URL(string: url.replacingOccurrences(of: " ", with: "%20")), let viewController = rootViewController { let fileViewerOpenDocument = FileViewerOpenDocument(viewController: viewController) fileViewerOpenDocument.openDocumentFromUrl(url:fileUrl, completion: { (inner: ErrorCompletionHandler) -> Void in do {