0

我已经像下面这样定义了 documentPicker,但我现在想获取上传的 pdf 的大小(以字节为单位)。

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

}

例如,它在如下图像的情况下工作:

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()
        }
4

1 回答 1

0

let bcf = ByteCountFormatter() bcf.allowedUnits = [.useBytes] bcf.countStyle = .file let string = bcf.string(fromByteCount: Int64(picdata.count))[.useBytes]在此字段 中根据需要更改大小单位。希望这可以帮助。

于 2020-01-27T15:42:59.280 回答