Avinash Vaghasiya
Avinash Vaghasiya

Reputation: 364

How can I get a icloud PDF file path to base64 string ? Swift 3

how to get pdf file path? and covert pdf file to base64 string

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    if controller.documentPickerMode == UIDocumentPickerMode.import {
        // This is what it should be
        //            self.txtName.text = String(contentsOfFile: url.path)
       //hear get base64 string
    }
}

Upvotes: 1

Views: 847

Answers (1)

blacker
blacker

Reputation: 798

this is the code for file to base64:

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    let fileData = try! Data.init(contentsOf: url)
    let base64String: String = fileData.base64EncodedString(options: NSData.Base64EncodingOptions.init(rawValue: 0))
}

Upvotes: 1

Related Questions