![](/img/trans.png)
[英]Not able to get .doc file from UIDocumentPickerViewController ios swift
[英]How to get file name and file size from UIDocumentPickerViewController in iOS 14?
我必须创建功能以上传 pdf 类型的一些文档,并且必须在上传之前使用从UIDocumentPickerViewController 's delegate
中选择的文件显示名称和文件大小。
如何获取其名称和文件大小?
在您的UIDocumentPickerDelegate
中,您最终将实现documentPicker(_:didPickDocumentsAt:)
,这将为您提供一个URL
数组。 您可以使用url.lastPathComponent
获取文件的名称。
关于文件大小,一旦你有相同的URL
从上面,你可以查询文件大小(可能在这里列出的解决方案: Swift - 从 url 获取文件大小):
do {
let attribute = try FileManager.default.attributesOfItem(atPath: url.path)
if let size = attribute[FileAttributeKey.size] as? NSNumber {
let sizeInMB = size.doubleValue / 1000000.0
}
} catch {
print("Error: \(error)")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.