I am using QuickLook
to show remote files(server side files). but with this i am not getting total image or file its just showing extension in QLPreviewController
why?
i have tried using this [enter link description here][1]
code: here urlAttach
will look like this https://UUUUU.com/storage/bids/1631792917-9297.jpeg
but showing in o/p only 1631792917-9297
why?
import QuickLook
class ViewVC: UIViewController, CustomCellDelegate {
let previewController = QLPreviewController()
var previewItems: [PreviewItem] = []
func numberOfPreviewItems(in controller: QLPreviewController) -> Int { previewItems.count }
func quickLook(url: URL) {
URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data, error == nil else {
// in case of failure to download your data you need to present alert to the user
// self.presentAlertController(with: error?.localizedDescription ?? "Failed to download the pdf!!!")
return
}
// you neeed to check if the downloaded data is a valid pdf
guard
let httpURLResponse = response as? HTTPURLResponse,
let mimeType = httpURLResponse.mimeType,
mimeType.hasSuffix("pdf")
else {
print((response as? HTTPURLResponse)?.mimeType ?? "")
// self.presentAlertController(with: "the data downloaded it is not a valid pdf file")
return
}
do {
// rename the temporary file or save it to the document or library directory if you want to keep the file
let suggestedFilename = httpURLResponse.suggestedFilename ?? "quicklook.pdf"
var previewURL = FileManager.default.temporaryDirectory.appendingPathComponent(suggestedFilename)
try data.write(to: previewURL, options: .atomic) // atomic option overwrites it if needed
// previewURL.hasHiddenExtension = true
let previewItem = PreviewItem()
previewItem.previewItemURL = previewURL
self.previewItems.append(previewItem)
DispatchQueue.main.async {
UIApplication.shared.isNetworkActivityIndicatorVisible = false
self.previewController.delegate = self
self.previewController.dataSource = self
self.previewController.currentPreviewItemIndex = 0
self.present(self.previewController, animated: true)
}
} catch {
print(error)
return
}
}.resume()
UIApplication.shared.isNetworkActivityIndicatorVisible = true
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { previewItems[index] }
func sharePressed(cell: ViewProposalTableVIewCell1) {
guard let index = tableView.indexPath(for: cell)?.row else { return }
let img = getBitDetails?.result?.bid?.get_attachments?[index].filename //bidAttatchment?[indexPath.item].filename
let urlAttach = "https://farfromadate.com/storage/app/public/bids/" + img!
let url = URL(string: urlAttach)
quickLook(url: url!)
}