से फ़ाइल का आकार प्राप्त करें मैं किसी दस्तावेज़ के यूआरएल पथ प्राप्त करने के लिए दस्तावेज़पिकर का उपयोग कर रहा हूं और फिर डेटाबेस पर अपलोड किया गया हूं। मैं फ़ाइल (पीडीएफ, txt ..) चुन रहा हूं, अपलोड काम कर रहा है लेकिन मैं फ़ाइल के आकार को सीमित करना चाहता हूं।स्विफ्ट - यूआरएल
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 –
धन्यवाद, लिंक ने मेरी मदद की। –
आपका स्वागत है ;-) –