0

i have defined the documentPicker like the following but i want now to get the size of the uploaded pdf in bytes.

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]){
self.parent.docData = // here the assigned value should be the size of the pdf

}

for example its working in case of image like the following:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
            let image = info[.originalImage] as! UIImage
            let picdata = image.jpegData(compressionQuality: 0.25)
            self.parent.picData = picdata!
            self.parent.picker.toggle()
        }
B25Dec
  • 2,301
  • 5
  • 31
  • 54
Alex
  • 267
  • 1
  • 3
  • 18

1 Answers1

0

let bcf = ByteCountFormatter() bcf.allowedUnits = [.useBytes] bcf.countStyle = .file let string = bcf.string(fromByteCount: Int64(picdata.count)) Change unit of size as required in [.useBytes] this field. Hope this helps.

B25Dec
  • 2,301
  • 5
  • 31
  • 54
  • thanks for your response but since i assign the value `string` to the `self.parent.docData = string` it shows mismatching data type. – Alex Jan 27 '20 at 15:52
  • Obviously it is returning a string, Try `picdata.count` for assigning `data` value to another `data`. – B25Dec Jan 27 '20 at 15:55
  • picData it works, but i need to define docData like picData. i am getting in the case of your try zero bytes – Alex Jan 27 '20 at 15:59
  • Okay use below one to convert your picked up File converted into `data` `let data = try! Data(contentsOf: urls[0])` I think data is the data file created from your file picked by document Picker. – B25Dec Jan 27 '20 at 16:07
  • which one please? all what i want is, to get the size of the doc in bytes from the urls.first of the firestore and assign it to the self.parent.docData – Alex Jan 27 '20 at 16:08