为什么我的 UIDocumentPickerViewController returns 我 url 无法访问?
why my UIDocumentPickerViewController returns me a url not reachable?
我正在使用 uIdocumentPickerViewController 在 firebase 中上传 pdf 文件,但是当我尝试上传它时,我收到一条错误消息,提示无法访问该文件。
这是我的 uidocumentPickerViewController 委托的代码:
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
let storageReference = Storage.storage().reference()
print(urls.first!)
storageReference.child((urls.first?.deletingPathExtension().lastPathComponent)!).putFile(from: urls.first!, metadata: nil){(_, err) in
if err != nil {
print((err?.localizedDescription)!)
return
}
print("success")
}
}
这是我在选择 pdf 文件后遇到的错误:
位于 URL 的文件:file:///private/var/mobile/Containers/Shared/AppGroup/7BE40C45-A4B5-4EE0-8AFF-789B2F93C1F6/File%20Provider%20Storage/Document%20PDF.pdf 无法访问。
域=NSCocoaErrorDomain 代码=257 xcode
我正在使用如下所示的 UIDocumentPicker,它工作正常:
首先我有一个枚举,
enum UploadFileType{
case photo
case file
}
然后一个结构:
struct UploadFileData {
var fileName: String
var fileType: UploadFileType
var fileData: NSData
}
var file: UploadFileData?
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let fileManager = FileManager.default
print(fileManager.fileExists(atPath: url.path))
let data = NSData(contentsOfFile: url.path)
guard let doc = data else {
// Utility.showAlert(message: Strings.ERROR.text, title: Strings.DOCUMENT_FORMAT_NOT_SUPPORTED.text, controller: self)
return
}
self.file = UploadFileData(fileName: "\(url)", fileType: .file, fileData: doc)
guard let dataFile = self.file?.fileData as Data? else {return}
}
我正在使用 uIdocumentPickerViewController 在 firebase 中上传 pdf 文件,但是当我尝试上传它时,我收到一条错误消息,提示无法访问该文件。
这是我的 uidocumentPickerViewController 委托的代码:
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
let storageReference = Storage.storage().reference()
print(urls.first!)
storageReference.child((urls.first?.deletingPathExtension().lastPathComponent)!).putFile(from: urls.first!, metadata: nil){(_, err) in
if err != nil {
print((err?.localizedDescription)!)
return
}
print("success")
}
}
这是我在选择 pdf 文件后遇到的错误:
位于 URL 的文件:file:///private/var/mobile/Containers/Shared/AppGroup/7BE40C45-A4B5-4EE0-8AFF-789B2F93C1F6/File%20Provider%20Storage/Document%20PDF.pdf 无法访问。
域=NSCocoaErrorDomain 代码=257 xcode
我正在使用如下所示的 UIDocumentPicker,它工作正常:
首先我有一个枚举,
enum UploadFileType{
case photo
case file
}
然后一个结构:
struct UploadFileData {
var fileName: String
var fileType: UploadFileType
var fileData: NSData
}
var file: UploadFileData?
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let fileManager = FileManager.default
print(fileManager.fileExists(atPath: url.path))
let data = NSData(contentsOfFile: url.path)
guard let doc = data else {
// Utility.showAlert(message: Strings.ERROR.text, title: Strings.DOCUMENT_FORMAT_NOT_SUPPORTED.text, controller: self)
return
}
self.file = UploadFileData(fileName: "\(url)", fileType: .file, fileData: doc)
guard let dataFile = self.file?.fileData as Data? else {return}
}