Return JPEG image in the Plugin


#1

I’m writing a custom HTTP handling for my web services. One of the service returns the binary data as blob for an image (after successful authentication). I’m writing this in Swift 4 to handle my URLSession below:

        if  let mimeType = response.mimeType, mimeType.hasPrefix("image") {
            let image = UIImage(data: data)!  //convert binary to jpeg image
            call.success(["data": image, "status":response.statusCode])
        }

As soon as the Capacitor plugin receive the call.sucess() data, I get this wierd error below and it does not even throw an error on Angular side.

[Capacitor Plugin Error] - MyPluginClass - GET - Unable to serialize plugin response as JSON.Ensure that all data passed to success callback from module method is JSON serializable!

I was wondering if I need to convert the blob data into base64 or not. Anyone has similar issue?

Thank you!
Jak