Ask Your Question
3

How can the directory structure be preserved when uploading local files to the UIWebview on an iPhone?

asked 2023-05-05 22:35:32 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-05 22:48:02 +0000

devzero gravatar image

One way to preserve the directory structure when uploading local files to the UIWebview on an iPhone is to use a file URL scheme.

First, get the local file path using a file manager:

let fileManager = FileManager.default
guard let filePath = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("myFolder/myFile.pdf") else {
    return
}

Then, create a file URL with the path and load it into the webview:

let fileURL = URL(fileURLWithPath: filePath.absoluteString)
let request = URLRequest(url: fileURL)
webView.load(request)

This approach will preserve the directory structure of the file when loading it into the webview.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-05 22:35:32 +0000

Seen: 10 times

Last updated: May 05 '23