documentPicker를 사용하여 문서의 URL 경로를 얻은 다음 데이터베이스에 업로드했습니다. 파일 (pdf, txt ..)을 선택합니다. 업로드가 작동하지만 파일 크기를 제한하려고합니다.Swift - url에서 파일 크기 얻기
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
self.file = url //url
self.path = String(describing: self.file!) // url to string
self.upload = true //set upload to true
self.attachBtn.setImage(UIImage(named: "attachFilled"), for: .normal)//set image
self.attachBtn.tintColor = UIColor.black //set color tint
sendbtn.tintColor = UIColor.white //
do
{
let fileDictionary = try FileManager.default.attributesOfItem(atPath: self.path!)
let fileSize = fileDictionary[FileAttributeKey.size]
print ("\(fileSize)")
}
catch{
print("Error: \(error)")
}
}
나는 문서 선택기 파일 어떻게 자신의 속성을 검색하는 방법을 절약 할 오류 메시지,이 파일이 존재하지 않는 얻을.
아마도 이것이 당신이 찾고있는 것입니다 : http://stackoverflow.com/questions/19315533/how-to-find-size-of-a-file-before-downloading-it-in-ios -7 –
감사합니다. 링크가 도움이되었습니다. –
iOS 11의 –