i am using documentPicker to get url path of any document and then uploaded to the database. I am choosing file (pdf, txt ..) , the upload is working but i want to limit the siz
Swift 4:
func sizePerMB(url: URL?) -> Double {
guard let filePath = url?.path else {
return 0.0
}
do {
let attribute = try FileManager.default.attributesOfItem(atPath: filePath)
if let size = attribute[FileAttributeKey.size] as? NSNumber {
return size.doubleValue / 1000000.0
}
} catch {
print("Error: \(error)")
}
return 0.0
}