don't have permissions to read image

I am getting the error, The file “21787.jpg” couldn’t be opened because you don’t have permission to view it.

how do I enable permissions to the app?
Answered by eleethesontai in 652362022
I figured it out. The url is scoped and so I had to direct it to start using the scoped url. like so,

Code Block func loadCover(result: Result<URL,Error>) {
        guard let selectedURL = try? result.get() else {return}
        if selectedURL.startAccessingSecurityScopedResource() {
            do {
                if let selectedData = try? Data(contentsOf: selectedURL) {
                    self.coverData = selectedData
                    if let uiImage = UIImage(data: selectedData) {
                        self.coverImage = Image(uiImage: uiImage)
                    }
                }
            } catch {
                print(error.localizedDescription)
            }
        }
        selectedURL.stopAccessingSecurityScopedResource()
    }


how do I enable permissions to the app?

Hard to answer without knowing how you put the file or how you are trying to open it.
Can you explain in detail?
Accepted Answer
I figured it out. The url is scoped and so I had to direct it to start using the scoped url. like so,

Code Block func loadCover(result: Result<URL,Error>) {
        guard let selectedURL = try? result.get() else {return}
        if selectedURL.startAccessingSecurityScopedResource() {
            do {
                if let selectedData = try? Data(contentsOf: selectedURL) {
                    self.coverData = selectedData
                    if let uiImage = UIImage(data: selectedData) {
                        self.coverImage = Image(uiImage: uiImage)
                    }
                }
            } catch {
                print(error.localizedDescription)
            }
        }
        selectedURL.stopAccessingSecurityScopedResource()
    }


don't have permissions to read image
 
 
Q