Skip to content

Commit

Permalink
[ios][document-picker] Fix copying to cache directory (expo#23102)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleqsio authored Jun 26, 2023
1 parent bf7bc3f commit 7c71f12
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/expo-document-picker/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

### 🐛 Bug fixes

- Fix `copyToCacheDirectory` on iOS. ([#23102](https://github.com/expo/expo/pull/23102) by [@aleqsio](https://github.com/aleqsio))
- Fixed Android build warnings for Gradle version 8. ([#22537](https://github.com/expo/expo/pull/22537), [#22609](https://github.com/expo/expo/pull/22609) by [@kudo](https://github.com/kudo))

## 11.4.0 — 2023-05-08
Expand Down
10 changes: 6 additions & 4 deletions packages/expo-document-picker/ios/DocumentPickerModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public class DocumentPickerModule: Module, PickingResultHandler {
}

private func readDocumentDetails(documentUrl: URL, copy: Bool) throws -> DocumentInfo {
let pathExtension = documentUrl.pathExtension
var newUrl = documentUrl

guard let fileSystem = self.appContext?.fileSystem else {
Expand All @@ -122,13 +121,16 @@ public class DocumentPickerModule: Module, PickingResultHandler {
}

if copy {
let directory = fileSystem.cachesDirectory.appending("DocumentPicker")
let path = fileSystem.generatePath(inDirectory: directory, withExtension: pathExtension)
let cacheDirURL = URL(fileURLWithPath: fileSystem.cachesDirectory)
let directory = cacheDirURL.appendingPathComponent("DocumentPicker", isDirectory: true).path
let fileExtension = "." + documentUrl.pathExtension
let path = fileSystem.generatePath(inDirectory: directory, withExtension: fileExtension)
newUrl = URL(fileURLWithPath: path)

try FileManager.default.copyItem(at: documentUrl, to: newUrl)
}

let mimeType = self.getMimeType(from: pathExtension)
let mimeType = self.getMimeType(from: documentUrl.pathExtension)

return DocumentInfo(
uri: newUrl.absoluteString,
Expand Down

0 comments on commit 7c71f12

Please sign in to comment.