Search code examples
iosswiftbase64pngpaw-app

iOS Swift base64encoding different than PAW app Base64 Encoding


Hoping to get some help with this. I am trying to post an image to a server and it requires base64 encoding of a PNG file. When I use the PAW app and encode the image everything shows up on the server beautifully. When I attempt to do the same with iOS Swift 4, the string produced is similar but also has differences and thus an incorrect image. Any idea of how to match the string that is correctly created in the PAW app in iOS. I have included code below along with screenshots of the strings (small samples) created.

Thanks!

    let image : UIImage = UIImage(named:"STG.png")!
    let imageData = UIImagePNGRepresentation(image)
    var base64String = imageData?.base64EncodedString(options: [])

Paw image

enter image description here


Solution

  • Ok went down several rabbit holes and found some folks with similar issues to this. I eventually solved it by switching over to Alamofire instead of using the native urlsession. I also found out the server I was posting to would allow for multipart/form-data as well which I ended up using for my request. I was unable to get that to work using the native urlsession either.